我已经编写了这个散点图,但我遇到了困难,可以使用一些帮助。我希望它包含两个图例:一个是仅一个因素的强度(如下所示),我能够做到,另一个将包括所有因素的形状,也许还有颜色 - 这个我做不到弄清楚。
这是我的数据集和代码:
lvl <- c("mid","mid","mid","mid","mid","mid","mid","mid","mid","mid","high","high","high","high",
"high","high","high","high","high","high","low","low","low","low","low","low","low",
"low","low","low")
x <- c(6.06,4.42,6.81,1.7,1.29,6.75,4.48,2.64,4.31,3.93,1.56,2.25,6.53,4,5.09,3.7,1.19,7.71,4.4,8.49,
4.14,5.37,7.1,2.94,1.75,2.49,1.37,1.22,9.29,1.37)
y <- c(4.17,1.41,6.79,1.72,1.45,7.29,4.49,2.72,1.34,6.66,3.94,2.84,7.3,3.97,4.95,9.03,5.23,8.77,1.13,
2.76,5.3,4.53,7.42,3.15,6.97,2.36,1.07,1.16,9.17,1.72)
z <- c(1.26,1.34,2.53,3.83,2.78,9.93,1.23,9.97,1.71,1.3,1.31,1,6.06,2.26,3.29,2.29,2.52,2.02,2.68,
9.7,2.9,1.7,6.65,9.54,2.05,1.06,3.59,1.16,2.99,1.14)
data <- data.frame(lvl,x,y,z)
low <- data %>% filter(lvl == "low")
mid <- data %>% filter(lvl == "mid")
high <- data %>% filter(lvl == "high")
ggplot(data = result_df, aes(x=x, y=y, color=lvl, shape=lvl)) +
geom_point(data = high, color = "gray81", shape = 18, size = 2, aes(color="high")) +
geom_point(data = mid, shape = 2, size = 4, stroke = 1.5, color = "black",aes(color="mid")) +
theme_classic()+
theme(legend.position="right")+
geom_point(data = low, size = 4, shape = 21, stroke = 1.5, color = "black", aes(fill = log10(z),
color = "low")) +
scale_fill_gradientn(name = "z Intensity" , colors = c("darkblue", "blue","red", "darkred"))+
scale_x_log10()+
scale_y_log10()
我尝试使用 scale_color_manual() 手动添加一个,但似乎没有这样做。我相信我的问题与我如何将参数映射到 aes 有关,但我整天都在尝试修改代码,但没有运气。显然我是一只小鹿,任何帮助都提前表示感谢。