gpt4 book ai didi

R scale_manual 使用2个字母作为点形

转载 作者:行者123 更新时间:2023-12-04 12:51:55 25 4
gpt4 key购买 nike

我有一个像这里这样的数据,想制作一个散点图,但我想使用国家名称的 2 个字母索引 (pop_char) 而不是点

dat <- structure(list(e1 = c(0.0128, -0.0328, -2e-04, 0.0171, 0.0036, 
-0.0043, -0.0049, -0.0355, -0.037, -0.003, 0.0061, -3e-04, -0.0401,
-0.0214, -0.0343, -0.0408, -0.0108, 0.0158, -0.0161, 0.0247,
-0.0068, -0.0208, -0.0199, 0.0084, 0.0032, -0.0126, 0.0068, -0.0048,
0.0138, 0.0012, 0.003, -0.0771, -0.0093, 0.008, -0.0367, 0.0145,
0.0278, 0.0081, -0.0136, -0.0172, 0.0062, -0.0231, 0.0233, -0.0413,
-0.0266, -0.0013, 0.0325, 0.0152, 0.0232, 0.0204), e2 = c(-0.0425,
-0.0519, -0.0023, -0.0245, -0.0511, -0.0422, -0.0505, -0.0516,
-0.0549, -0.0565, -0.0523, -0.0569, -0.0503, -0.0411, -0.0622,
-0.0716, -0.0529, -0.0413, -0.0447, -0.0316, -0.0537, -0.0622,
-0.0409, -0.0347, -0.0513, -0.0467, -0.0401, -0.0565, -0.0461,
0.0094, -0.0579, -0.0215, -0.0514, -0.0573, -0.0548, -0.0286,
-0.0676, 0.0183, -0.0618, -0.0529, -0.0517, -0.0507, -0.0276,
-0.0588, -0.063, -0.046, -0.0496, -0.0652, -0.0231, -0.0412),
pop_name = structure(c(4L, 11L, 9L, 5L, 2L, 11L, 11L, 11L,
7L, 11L, 2L, 2L, 11L, 3L, 11L, 11L, 6L, 6L, 6L, 5L, 7L, 11L,
7L, 6L, 11L, 11L, 6L, 11L, 7L, 9L, 2L, 8L, 11L, 2L, 1L, 6L,
10L, 9L, 11L, 7L, 7L, 3L, 6L, 11L, 11L, 11L, 5L, 4L, 5L,
5L), .Label = c("Albania", "Bosnia", "Bulgaria", "Croatia",
"Czech_Republic", "Hungary", "Romania", "Slovakia", "Switzerland",
"Ukraine", "Yugoslavia"), class = "factor"), pop_char = structure(c(4L,
11L, 9L, 5L, 2L, 11L, 11L, 11L, 7L, 11L, 2L, 2L, 11L, 3L,
11L, 11L, 6L, 6L, 6L, 5L, 7L, 11L, 7L, 6L, 11L, 11L, 6L,
11L, 7L, 9L, 2L, 8L, 11L, 2L, 1L, 6L, 10L, 9L, 11L, 7L, 7L,
3L, 6L, 11L, 11L, 11L, 5L, 4L, 5L, 5L), .Label = c("Al",
"Bo", "Bu", "Cr", "Cz", "Hu", "Ro", "Sl", "Sw", "Uk", "Yu"
), class = "factor")), .Names = c("e1", "e2", "pop_name",
"pop_char"), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
"49", "50"))

我想到了:

library(ggplot2)
ggplot() +
geom_point(data=dat, mapping=aes(e1,e2,shape=pop_char,colour=pop_char,size=5)) +
scale_shape_manual(values=pop_char)

但绘制的字母不是 pop_char 列。

最佳答案

如果您坚持使用字母,则可以改用 geom_text,但会出现大量过度绘制。

p1 <- ggplot(dat, aes(x=e1,y=e1, colour=pop_char))+
geom_text(aes(label=pop_char)) + theme(legend.position="none")
p1

enter image description here

关于R scale_manual 使用2个字母作为点形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32757680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com