我想繪制一個散點圖,其中點的形狀和大小不同。重要的是,我希望每個形狀周圍都有黑色邊框。資料框如下:
> 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")

我怎樣才能做到這一點?
uj5u.com熱心網友回復:
您需要將顏色美學更改為填充美學,并使用形狀 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")

uj5u.com熱心網友回復:
我以前沒見過geom_quasirandom,但它可能需要你利用這個colour論點,所以試試
geom_quasirandom(groupOnX=TRUE, colour = "black")
然后重新運行。如果這不起作用,則該函式選擇的形狀沒有可以更改的邊框。如果是這樣,您將需要手動選擇這些。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/450641.html
