我有一个包含31个级别的分类数据的数据集。我想用ggplot在散点图中显示它们的分布,但我想特别强调一些数据点,比如这里的红色圆圈:
我倾向于在数据点[x = 10,y = 6]处的观察点周围有一个红色虚线圆圈。优选地,该解决方案是可持续的,但是手动盘旋建议也是欢迎的:)。这是我的剧本
library(ggplot2)
#dataframe
df1 <- data.frame(name = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "b", "c", "d", "e"),
n = rep(1:31, 1),
value = c(3, 2, 5, 1, 1, 6, 7, 9, 8, 6, 10, 11, 11, 11, 13, 15, 17, 16, 18, 18, 20, 20, 23, 22, 22, 23, 25, 26, 28, 29, 29))
#set correct data type
df1$name <- as.factor(df1$name)
#produce color vector
color <- grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)]
col_sample <- sample(color, 31)
col_sample <- as.vector(col_sample)
#scatterplot
median_scatter <- ggplot(data = df1,
aes(x = n,
y = value,
colour = name))
median_scatter +
geom_point() +
scale_colour_manual(values=col_sample)