我想要一個散點圖,其中不同的形狀大小顯示不同的位置(只有兩個位置)。
資料顯示在這里:
Sample Name εNd stratigraphic column sample number
B8 -4.887223024 8.34 ND
B7B8 -5.723139056 8.27 ND
MO2400 -6.639290394 7.2 M
SHARK 2 -6.349256446 7 M
M.FISH -6.100998712 7.1 M
MO2376 -7.689046402 -6 M
ABOVE UPPER -8.306593254 -6.53 ND
NIO 38 -8.90688489 -8.07 ND
NIO 39 -7.243909917 -8.16 ND
T-4 TO T-5 -7.700379025 -12 ND
T-2 TO T-3 -8.532019275 -12.47 ND
T1 TO T0 -6.894687774 -13.1 ND
我試過使用這段代碼:
ggplot(data=nd, aes(x=nd$εNd, y= nd$`stratigraphic column`)) geom_point(size=4, shape=factor(nd$`sample number`)) ggtitle(expression(epsilon*"Neodymium in Manitoba Escarpment")) xlab(~epsilon*"Nd")
它給了我這張圖:

我不喜歡這些形狀的外觀,也沒有傳說。所以我嘗試使用 ggplot 中的組走不同的路線:
ggplot(data=nd, aes(x=εNd, y= `stratigraphic column`, group='sample number')) geom_point(aes(shape='sample number'), size=4) scale_shape_manual(values=c(16,17)) ggtitle(expression(epsilon*"Neodymium in Manitoba Escarpment")) xlab(~epsilon*"Nd") ylab("Stratigraphic Position")
我得到了這個作為輸出圖:

這個不會根據位置改變形狀,但有一個圖例。
我嘗試將“樣本編號”列的資料型別從字符更改為因子,但這沒有幫助。
提前致謝。
uj5u.com熱心網友回復:
您需要將樣本編號映射到形狀美學:
ggplot(nd, aes(εNd, `stratigraphic column`))
geom_point(size = 4, aes(shape = `sample number`))
ggtitle(expression(epsilon*"Neodymium in Manitoba Escarpment"))
xlab(~epsilon*"Nd")
theme_light()

從問題中獲取的可重復形式的資料
nd <- structure(list(`Sample Name` = c("B8", "B7B8", "MO2400", "SHARK 2",
"M.FISH", "MO2376", "ABOVE UPPER", "NIO 38", "NIO 39", "T-4 TO T-5",
"T-2 TO T-3", "T1 TO T0"), eNd = c(-4.887223024, -5.723139056,
-6.639290394, -6.349256446, -6.100998712, -7.689046402, -8.306593254,
-8.90688489, -7.243909917, -7.700379025, -8.532019275, -6.894687774
), `stratigraphic column` = c(8.34, 8.27, 7.2, 7, 7.1, -6, -6.53,
-8.07, -8.16, -12, -12.47, -13.1), `sample number` = c("ND",
"ND", "M", "M", "M", "M", "ND", "ND", "ND", "ND", "ND", "ND")),
class = "data.frame", row.names = c(NA, -12L))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/453812.html
上一篇:GGPLOT中的可變圖例值和顏色
