我正在學習GGPLOT2,我不明白爲什麼這不起作用:爲什麼ggplot中的這個命令返回一個錯誤?
p <- ggplot(diamonds, aes(x = carat))
p <- p + layer(
geom = "point",
stat = "identity"
)
p
Error in as.environment(where) : 'where' is missing
你知道爲什麼嗎?
我正在學習GGPLOT2,我不明白爲什麼這不起作用:爲什麼ggplot中的這個命令返回一個錯誤?
p <- ggplot(diamonds, aes(x = carat))
p <- p + layer(
geom = "point",
stat = "identity"
)
p
Error in as.environment(where) : 'where' is missing
你知道爲什麼嗎?
我認爲問題是,你還沒有指定使用什麼的y值。 ggplot2與繪製點的基礎圖形相比,其索引值不具有相同的默認值。與stat="identity"
使用geom_point()
你需要這樣的:
p<-ggplot(diamonds, aes(x=carat, y=cut))
p+layer(geom="point", stat="identity")
或更常見
p+geom_point(stat="identity")
或其他但是你想嘗試繪圖數據。
一般不要使用layer
建立一個陰謀。相反,您使用geom
或stat
。 p + geom_point()
將繪製你正在尋找的東西。我建議通過gplot2
文檔中的一些示例。
正確的,但通過使用層我只是想知道究竟是什麼GEOM和統計以及它們如何相互作用 – Wicelo
您的數據和美學邁向'layer'電話給你一個原始對象回來,但我不知道該怎麼用它做:'層(數據= diamons,AES(X =脫字符號),的geom = '點',STAT = '身份')'。但是,'stat ='identity''在這裏相當多餘。 – Justin