【发布时间】:2021-08-19 18:49:17
【问题描述】:
我希望这张图表上的每条趋势线都具有不同的形状。例如,“男孩”趋势线将是虚线,而“女孩”趋势线将是实线。我在 R 中使用ggplot2 库。这是我的代码。
dr <- ggplot(Tempdata,
aes(x = Tempdata$EffortfulControl,
y = Tempdata$sqrt_Percent.5,
color = Tempdata$Sex1M,
shape = Tempdata$Sex1M)) +
geom_point(aes(shape = Tempdata$Sex1M,
color = Tempdata$Sex1M),
show.legend = FALSE) +
scale_shape_manual(values=c(16,17))+
geom_smooth(method=lm,se=FALSE,fullrange=TRUE) +
labs(x = "xaxis label",
y = "yaxis label",
fill = "") +
xlim(3,7) +
ylim(0,10)
dr +
scale_colour_grey(start = 0.0,
end = .7 ,
guide_legend(title = "")) +
theme_classic()
根据@nebroth 的建议更新了代码
dr <- ggplot(Tempdata,
aes(x=Tempdata$EffortfulControl,
y=Tempdata$sqrt_Percent.5,
color=Tempdata$Sex1M,
shape=Tempdata$Sex1M,
linetype=Tempdata$Sex1M)) + geom_point(aes(shape=Tempdata$Sex1M,
color=Tempdata$Sex1M),
show.legend = FALSE) +
scale_shape_manual(values=c(16,17))+ geom_smooth(method=lm,se=FALSE,fullrange=TRUE) +
labs(x="xaxislabel",
y = "yaxis label", fill= "") +
xlim(3,7) +
ylim(0,10)
dr +
scale_colour_grey(start = 0.0,
end = 0.4,
guide_legend(title = "")) +
theme_classic()
【问题讨论】:
标签: r ggplot2 graph data-visualization