更新时间:2023-09-13 16:45:34
只需添加将y映射到其他变量的geom。为简单起见,我将一些美学元素移至geom_boxplot。
Simply add an geom mapping the y to a different variable. For the sake of simplicity, I moved some of the aesthetics to the geom_boxplot.
MyPlot <- ggplot(MyData, aes(x=Month)) + geom_boxplot(aes(y=Note, fill=Treatment)
MuPlot <- MyPlot + geom_pointline(aes(y=Optimum), colour="green", stroke="black")
但是,这不会为您添加图例,因为ggplot2不支持相同比例的多种编码(即同时使用处理和单独的颜色变量)。
This will however not add you points to the legend, as ggplot2 does not support multiple encodings of the same scale (i.e. using both Treatment and a separate variable for colour).
geom geom_pointline
来自柠檬
The geom geom_pointline
is from the 'lemon' package.
第二点,尝试第二行:
MuPlot <- MyPlot + geom_pointline(aes(y=Optimum, colour="Optimum"), stroke="black") + scale_colour_manual(values('Optimum'='green'))