我想在ggplot2中创建一个散点图,其中带有"更改"等于"是"是红点,其余的是灰色的,而点是"重要的"等于"重要"有额外的绿色寄宿生,其余的有一个灰色寄宿生。 这是我的尝试:
structure(list(a = c(4.31316551, 5.7663368, 2.49063318, 5.83090286,
3.11188057, 9.58084417, 4.08696886, 3.11188057, 6.43800344, 1.77771123,
4.22594833), b = c(0.848363512, 0.045492721, 0.049883076, 0.136202457,
0.572585532, 0.175069609, 0.000782666, 0.848363512, 0.254619199,
0.378181529, 0.848363512), Significant = structure(c(1L, 2L,
2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L), .Label = c("no", "yes"), class = "factor"),
Change = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L,
1L, 1L), .Label = c("no", "yes"), class = "factor")), .Names = c("a",
"b", "Significant", "Change"), class = "data.frame", row.names = c(NA,
-11L))
并输入数据:
<boolProp name="HTTPArgument.always_encode">false</boolProp>
答案 0 :(得分:1)
两种不同的方法:
ggplot(data = df, mapping = aes(x=a,y=b)) +
geom_point(shape = 21, size=3, mapping = aes(fill=Change, color=Significant)) +
scale_fill_manual(values=c("grey", "red")) +
scale_color_manual(values=c("grey","green"))
ggplot(data = df, mapping = aes(x=a,y=b)) +
geom_point(data=df[df$Significant == "no",], color="grey", size=5) +
geom_point(data=df[df$Significant == "yes",], color="green", size=5) +
geom_point(size=3, mapping = aes(color=Change)) +
scale_color_manual(values=c("grey","red"))