我試圖創建一個圖表,其中的mpg點將顯示為灰點和qsec綠色。問題是我希望 2 個點像內圈和外圈一樣顯示。當然,它們的大小應該類似于它們顯示的值。
library(ggplot2)
library(plotly)
p <- mtcars%>%ggplot(aes(x=wt))
geom_point(aes(y=x,size=mpg*2),color="gray")
geom_point(aes(y=x,size=qsec),color="darkolivegreen")
scale_x_continuous(n.breaks=14)
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank())
labs(x="")
p
ggplotly(p)
uj5u.com熱心網友回復:
您尚未指定 y 軸變數,因此沒有可繪制的內容。目前您的代碼會引發錯誤,因為x在mtcars.
例如,如果您希望hp在 y 軸上,您的代碼將按預期作業。
library(ggplot2)
library(plotly)
p <- mtcars %>% ggplot(aes(wt))
geom_point(aes(y = hp, size = mpg * 2), color = "gray")
geom_point(aes(y = hp, size = qsec), color = "darkolivegreen")
scale_x_continuous(n.breaks = 14)
theme(legend.position = 'none',
axis.title.y = element_blank(),
axis.text.y = element_blank())
labs(x = "")
ggplotly(p)

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/432004.html
