gpt4 book ai didi

r - 单行图例(错误 : Don't know how to add o to a plot)

转载 作者:行者123 更新时间:2023-12-01 13:43:23 26 4
gpt4 key购买 nike

我希望在我的情节之上的图例是单行的。我尝试使用 guide_legend(nrow=1)guides(fill=guide_legend(nrow=1,byrow=TRUE)) 两者都会产生相同的错误 Error : 不知道如何将 o 添加到绘图中

示例图片

enter image description here

这是我的代码和数据:

date = as.Date(c("2015-06-09","2015-06-09","2015-06-09","2015-06-09","2015-06-09","2015-06-09","2015-06-09, 2015-06-10","2015-06-10","2015-06-10","2015-06-10","2015-06-10","2015-06-10","2015-06-10","2015-06-10"))
ph = c(8.1, 7.66, 6.71, 8.23, 8.23, 8.21, 7.9,8.1, 7.66, 6.71, 8.23, 8.23, 8.21, 7.9)
step = c("Step1","Step2","Step3","Step4","Step5","Step6","Step7","Step1","Step2","Step3","Step4","Step5","Step6","Step7")

df = data.frame(date,ph,step)

df_plot <- ggplot(df,aes(x=date, y=ph, group=step,color=step, shape=step)) +
scale_shape_manual(values=c(1,2,3,4,5,6,7)) + geom_point(size=2) + geom_line() +
theme(legend.position = "top") + guide_legend(nrow=1)

如有任何帮助,我们将不胜感激!

最佳答案

您可以将 guide_legend() 放在 scale_shape_manual() 中。以下对我有用:

ggplot(df,aes(x=date, y=ph, group=step,color=step, shape=step)) +
scale_shape_manual(values=c(1,2,3,4,5,6,7), guide = guide_legend(nrow=1)) +
geom_point(size=2) + geom_line() +
theme(legend.position = "top")

关于r - 单行图例(错误 : Don't know how to add o to a plot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37886752/

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