我有一个叠加了列和点的数据集。绘图相当简单,但我似乎无法让 geom_point 显示为单独的图例。相反,它默认将两者结合起来。
我尝试将这些点添加为单独的数据框,将映射点添加为因子,以及在论坛上找到无穷无尽的功能。有什么提示吗?
下面的简化示例:
library(ggplot2)
Site <- c("A", "B", "C", "A", "B", "C")
Year <- c(2020, 2020, 2020, 2019, 2019, 2019)
Geomean <- c(65,184,27,21,67,51)
Historical.Geomean <- c(76,81,44,76,81,44)
df <- data.frame(Site, Year, Geomean, Historical.Geomean)
df$Year <- as.factor(df$Year)
fw_ecoli_plot <-
ggplot(df) +
geom_col(aes(x=Site, y=Geomean, fill=Year), position="dodge") +
geom_point(aes(x=Site, y=Historical.Geomean),
color="black", pch=18, show.legend = T) +
theme_bw()
fw_ecoli_plot