gpt4 book ai didi

r - 使用 ggplot 绘制数据

转载 作者:行者123 更新时间:2023-12-04 02:29:59 24 4
gpt4 key购买 nike

我也在尝试用黑线图例绘制我的数据,但我不知道如何才能使“MYLINE”出现在 MY2 下方的右侧?以及如何控制这条线的颜色和属性,例如颜色、粗细……?

MY1_DIS_REF$METHOD <- "MY1"
MY1_plot<-MY1_DIS_REF[,-c(5,6,7)]
MY2_DIS_REF$METHOD <- "MY2"
MY2_plot<-MY2_DIS_REF[,-c(5,6,7)]
MY1andMY2_PLOT <- rbind(MY1_plot,MY2_plot)

ggplot()+
geom_point(data=MY1andMY2_PLOT,aes(X,Y,color=METHOD),alpha=0.5)+
geom_path(data=line,aes(V1,V2,group=B1,),size=1)+
xlab("X")+
ylab("Y")+
facet_wrap(~B1,scales = "free")+
theme_bw()+coord_flip()

enter image description here

最佳答案

您可以通过使用与当前图例所使用的美学不同的美学来为线条添加单独的图例:

ggplot()+
geom_point(data=MY1andMY2_PLOT,aes(X,Y,color=METHOD),alpha=0.5)+
geom_path(data=line,aes(V1,V2, group=B1, linetype = "Myline"), size=1)+
xlab("X")+
ylab("Y")+
facet_wrap(~B1,scales = "free")+
theme_bw()+coord_flip()

enter image description here

你可以用美学之外的论据改变其他美学,例如厚度由 size 控制:

ggplot()+
geom_point(data=MY1andMY2_PLOT,aes(X,Y,color=METHOD),alpha=0.5)+
geom_path(data=line,aes(V1,V2, group=B1, linetype = "Myline"), size=3)+
xlab("X")+
ylab("Y")+
facet_wrap(~B1,scales = "free")+
theme_bw()+coord_flip()

enter image description here

您可以通过编辑色标来更改颜色(默认为红色和蓝色):

ggplot()+
geom_point(data=MY1andMY2_PLOT,aes(X,Y,color=METHOD),alpha=0.5)+
geom_path(data=line,aes(V1,V2, group=B1, linetype = "Myline"), size=1)+
xlab("X")+
ylab("Y")+
facet_wrap(~B1,scales = "free")+
theme_bw()+coord_flip() +
scale_color_manual(values = c("orange", "pink"))

enter image description here

编辑:更改线条颜色:

ggplot()+
geom_point(data=MY1andMY2_PLOT,aes(X,Y,color=METHOD),alpha=0.5)+
geom_path(data=line,aes(V1,V2, group=B1, linetype = "Myline"), size=3, colour = "blue") +
xlab("X")+
ylab("Y")+
facet_wrap(~B1,scales = "free")+
theme_bw()+coord_flip()

enter image description here

关于r - 使用 ggplot 绘制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64863493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com