我正在嘗試使用資料框在 ggplot2 中創建一個簡單的線圖,但結果未按預期顯示。
這是重現資料的代碼:
tograph<-data.frame(PANEL=13:22,total=c(10,20,30,40,50,60,70,80,90,100))
當我在 ggplot2 中繪制結果時,它只會在 PANEL=1 處創建一條垂直線(所以此時不??會讓我發布影像)
ggplot(data=tograph,aes(x=PANEL,y=total)) geom_line()
作為一個健全的檢查,我運行了一些我在另一篇文章中找到的示例資料,以確保它不是我安裝的 R 所獨有的并且它作業正常
xValue <- 1:10
yValue <- cumsum(rnorm(10))
data <- data.frame(xValue,yValue)
# Plot
ggplot(data, aes(x=xValue, y=yValue))
geom_line()
同樣,在基礎 R 中繪制我的預期資料也可以正常作業,但出于美學原因,我更喜歡在 ggplot2 中設定它:
plot(tograph$PANEL,tograph$total,type="l")
非常感謝任何有關解決此問題的幫助。
uj5u.com熱心網友回復:
看起來像是PANELggplot2 中受保護的 data.frame 變數名。使用不同的變數名,例如panel.
(我懷疑它與 ggplot2 如何處理傳入資料以準備繪制它有關。例如從
ggplot(data.frame(panel=13:22,
total=c(10,20,30,40,50,60,70,80,90,100)),
aes(panel,total)) geom_point()

uj5u.com熱心網友回復:
如果要保留 PANEL 變數名稱,可以使用以下代碼:
ggplot(data=tograph,aes(x=tograph$PANEL,y=tograph$total))
geom_line()

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/530799.html
標籤:rggplot2图形几何
