我正在使用ggplot2在R中绘制一个图。这是一个线条图,每个观察点都有点,这些点代表p值。其中有三个不重要,我希望这些点以不同的方式显示(其他任何形状/颜色都无关紧要)。现在我不确定该怎么做了。
我尝试了scale_shape_manual(values = c(valueA,valueB,valueC))和scale_color_manual,但没有得到任何结果。也没有错误消息,只是什么都没有发生。
有人能帮上忙吗?
ggplot(data = dataframe) +
geom_line(aes(x=Time, y=Treatment), color="#00AFBB")+
geom_point(aes(x=Time, y=Treatment)) +
scale_y_reverse()+
scale_x_continuous( breaks = c(1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20))谢谢!
--
编辑:这里是一个可重现的样本(我希望它可以工作?):
A <- c(1,2,3,4,5)
B <- c(1,2,3,4,5)
df <- data.frame(cbind(A, B))发布于 2021-06-03 01:48:55
这里有一个例子,希望能对你有所帮助。我使用scale_color_identity和scale_shape_identity,因为我的数据(在本例中是通过if_else语句创建的)指定了我想要使用的文字颜色/形状。
Time <- c(1,2,3,4,5)
Treatment <- c(1,2,3,4,5)
df <- data.frame(Time = 1:5, Treatment = 1:5)
ggplot(data = df) +
geom_line(aes(x=Time, y=Treatment), color = "#00AFBB") +
geom_point(aes(x=Time, y=Treatment,
shape = if_else(Treatment < 5, 18, 1),
color = if_else(Treatment < 5, "#00AFBB", "black")), size = 4) +
scale_y_reverse()+
scale_x_continuous( breaks = 1:20) +
scale_color_identity() +
scale_shape_identity()

https://stackoverflow.com/questions/67809518
复制相似问题