Graphics/
在產生圖形時,請務必使用相對路徑。
你拿到的程式碼代表位於 R/ 目錄中的一支指令稿。
本練習屬於課程
R 防禦式程式設計
練習說明
- 將
read_csv()的引數改為使用相對路徑。 - 將
ggsave()的引數改為使用相對路徑。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library("ggplot2")
library("readr")
# Show the file/directory structure
list.files(".")
# Change to relative paths and load the data
battles <- read_csv("/home/repl/survival/input/battles.csv")
g <- ggplot(battles) + geom_bar(aes(Location)) # Bar chart
# Change to relative paths and save the data
ggsave(filename = "/home/repl/survival/graphics/locations.pdf", plot = g)