我有以下样例散点图:
我想go 掉"项目绩效"图例方块上的黑点.我只想让图例显示不同 colored颜色 的线条类型及其标签.有人知道怎么做吗?我第一次使用ggnewScale来显示这个同时使用geom_point和geom_vline的散点图的图例.我不知道如何在大范围内操纵这些传说.
以下是我的代码:
#sample data
df <- data.frame(cohort=c("20-21","20-21","20-21","20-21","21-22","21-22","21-22","21-22","22-23","22-23","22-23","22-23"),
sat=c(1220, 1020, 850, 1160, 920, 970, 1170, 830, 730, 1200, 1090, 880),
project=c(2.5, 2.2, 2.6, 2.8, 2.9, 3.0,3.0, 2.8, 2.0, 2.5, 1.8, 2.0),
pass_sat=c("Met Threshold", "Met Threshold", "Did Not Meet Threshold", "Did Not Meet Threshold",
"Met Threshold", "Did Not Meet Threshold", "Did Not Meet Threshold","Met Threshold",
"Met Threshold", "Did Not Meet Threshold", "Did Not Meet Threshold","Met Threshold"))
threshold <- data.frame(x = c(2, 2.7), group = c("pass", "scholarship eligible"),
color = c("red", "darkgreen"), line=c("dashed", "solid"), stringsAsFactors = FALSE)
group.colors <- c("Overall" ="#FFD580", "ELA" = "#CBC3E3", "Math" = "lightyellow", "Essential Skills"="lightpink")
#sample plot
#total sat against total project score
ggplot(df, aes(x = project, y = sat)) +
geom_point() +
facet_grid(.~cohort) +
scale_x_continuous(limits = c(1, 3), breaks = seq(1, 3, by = 0.5)) +
geom_smooth(method = "lm", se = F) +
labs(x = "Total Project score", y = "Total SAT") +
stat_cor(method = "pearson", size = 2.6, digits= 2) +
geom_vline(
aes(xintercept = x, colour = group, linetype = group),
threshold
)+
scale_linetype_manual(
name = "Project Performance",
values = c(pass = "solid", "scholarship eligible" = "dashed")
) +
scale_color_manual(
name = "Project Performance",
values = c(pass = "red", "scholarship eligible" = "darkgreen")
) +
new_scale_color() +
geom_point(aes(colour = pass_sat),
show.legend = TRUE) +
scale_color_manual(name = "SAT Performance", values = c("Met Threshold" = "purple", "Did Not Meet Threshold" = "black")) +
labs(title= "Total SAT by Overall Project Score, by Year")
谢谢!