開始使用免費開始

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)
編輯並執行程式碼