我正在尝试通过x,y采样坐标绘制结果度量(此处为树突棘密度)。我已经通过密度值指定了它们的颜色。现在,我想绘制我的数据子集(又称所有数据,而不是所有数据,仅限于实验组,例如“少年男性”),但从总体脊柱密度分布中生成点颜色。
我对ggplot还不是很熟悉,所以我尝试的第一件事是
plot1 <- ggplot(juvmales, aes(x=ML, y=DV, color=spines$Density)) +
geom_point(size=3.5) +
expand_limits(y=-1850)
### color plot of density by coordinates ALL DATA
plot1 <- ggplot(spines, aes(x=ML, y=DV, color=Density)) +
geom_point(size=3.5) +
expand_limits(y=-1850)
plot1 + scale_color_gradient(low="blue",high="red", space="Lab")
### color plot of density by coordinates juvenile males
plot2 <- ggplot(juvmales, aes(x=ML, y=DV, color=Density)) +
geom_point(size=3.5) +
expand_limits(y=-1850)
plot2 + scale_color_gradient(low="blue",high="red", space="Lab")
答案 0 :(得分:0)
获取整体数据范围并将其分配给变量
spine_ovrall_rnge <- range(spines$Density)
# and then add a zero for midpoint
spine_ovrall_rnge0 <-sort(c(0,spine_ovrall_rnge)# for assigning colors
#Use below to add to plot2 call
+scale_fill_gradientn(limits = spine_ovrall_rnge,
colours=c("blue", "darkmagenta", "red"),
breaks=spine_ovrall_rnge0, labels=format(spine_ovrall_rnge0))