我想使用 ggplot 来显示点和线,但我希望有两个图例 - 一个用于点,一个用于线。
我设法使用下面的代码做到了这一点,但由于某种原因,geom_point 中的“大小”选项不再响应,并且它们被困在您可以在图像中看到的相当丑陋的大小上 。
请注意,我选择 stroke = NA 因为我不希望这些点有边框。代码如下。
有任何想法吗?
ggplot(data = plot_data) +
geom_point(aes(x = z.1, y = obs, fill = treatcat), alpha = 0.4, shape = 21, stroke = NA, size = 1) +
geom_line(aes(x = z.1, y = under, colour = "True"), linetype = "dashed") +
geom_line(aes(x = z.1, y = crude, colour = "Crude"), size = 1.5) +
scale_fill_manual(name = "Treatment",
values = c("0" = "#F8766D", "1" = "#C77CFF"),
breaks = c("0", "1"),
labels = c("Untreated", "Treated")) +
scale_colour_manual(name = "Model",
values = c("Crude" = "orange", "True" = "black"),
breaks = c("Crude", "True"),
labels = c("Crude", "True")) +
ylim(-30,27.5) +
theme(plot.title = element_text(size = "12")) +
labs(title = "Fitted Values for Crude Model", x = "Z", y = "Y(1)")