我正在嘗試在此平行圖中連接裝置,但出現此錯誤:
錯誤:提供給連續刻度的離散值
這是我的代碼:
mdf <- melt(df, id.vars = "sub_i")
class_info <- summarise(group_by(mdf,variable),value = mean(value))
ggplot(data = mdf,
mapping = aes(x=variable,
y=value,
color=(sub_i)))
geom_line(aes(group = sub_i),size=0.3)
geom_point(shape=1)
theme(legend.position="none")
labs(y = "Correlation",x="")
scale_color_gradientn(colours = rainbow(30))
# mean point and lines
geom_point(data = class_info, color="black", size =4,alpha=0.8)
geom_line(data = class_info, mapping=aes(color="black"))
這是 30x4 “df” 頭:
sub_i msub_r indiv_r msub_null
1 1 0.06249845 0.066307886 -0.002599296
2 2 -0.03429027 0.068107218 -0.007419282
3 3 0.04417815 0.052935044 0.014339405
4 4 0.03578681 0.004392912 0.004940727
5 5 0.02851687 -0.075268277 -0.005774686
6 6 0.04049765 0.034980933 -0.002489030
沒有最后一行,一切都很好,我明白了,但手段沒有聯系。 數字
uj5u.com熱心網友回復:
問題是您使用的是連續色標,但"black"在color最后一個geom_line. 而是將顏色設定為引數并用于group=1“連接”點。
library(ggplot2)
ggplot(
data = mdf,
mapping = aes(
x = variable,
y = value,
color = (sub_i)
)
)
geom_line(aes(group = sub_i), size = 0.3)
geom_point(shape = 1)
theme(legend.position = "none")
labs(y = "Correlation", x = "")
scale_color_gradientn(colours = rainbow(30))
geom_point(data = class_info, color = "black", size = 4, alpha = 0.8)
geom_line(data = class_info, mapping = aes(group = 1), color = "black")

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