我想绘制一个散点图,其中点的形状和大小不同。重要的是,我希望每个形状周围都有黑色边框。数据框如下:
> dput(human.correlations[1:5, c(2:5)])
structure(list(variable = c("Caudate.Astrocytes", "Caudate.dSPNs_eccentric",
"Caudate.dSPNs_matrix", "Caudate.dSPNs_patch", "Caudate.Endothelia1"
), correlation = c(0.746433126, 0.80268901, 0.783305333, 0.790514121,
0.706648893), Number.Of.Wins = c(0L, 0L, 0L, 0L, 0L), Region = c("Caudate",
"Caudate", "Caudate", "Caudate", "Caudate")), row.names = c(NA,
5L), class = "data.frame")
mid <- 0.6 #set the midpoint
#scatterplot of figure
ggplot(human.correlations, aes(y=Number.Of.Wins, x=Region, color = correlation, shape = Cell.Class, size=Number.Of.Wins))+
geom_quasirandom(groupOnX=TRUE)+
scale_color_gradient2(midpoint=mid, low="white", mid="yellow", high="red")+
scale_size(range = c(2,9))+
theme_bw()+
ylab("Number of Wins")+
xlab("Brain region")
我怎样才能做到这一点?
您需要将颜色美学更改为填充美学,并使用形状 21、22、23,它们是同时具有填充和颜色的轮廓形状。将它们的颜色设置为黑色以获得黑色轮廓。
请注意,您的示例数据框缺少Cell.Class
实际映射到您的形状的列,因此我添加了一个随机的:
# Make example reproducible
human.correlations$Cell.Class <- c("Excitatory", "Glia", "Inhibitory Neuron",
"Glia", "Excitatory")
然后是绘图代码
library(ggplot2)
library(ggbeeswarm)
ggplot(human.correlations, aes(y = Number.Of.Wins, x = Region, fill = correlation,
shape = Cell.Class, size = Number.Of.Wins)) +
geom_quasirandom(groupOnX = TRUE, color = 'black') +
scale_fill_gradient2(midpoint = mid, low = "white", mid = "yellow", high = "red") +
scale_size(range = c(2, 9)) +
scale_shape_manual(values = c(21, 22, 23)) +
theme_bw() +
ylab("Number of Wins") +
xlab("Brain region")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句