如何删除geom_point ggplot中的点组

Nic*_*abo 5 r ggplot2

我的情节有问题。我只想显示 A 组中的点,而不是每个名称中的点。这是一个例子:

name <- c("a","b","c","d")
df <- data.frame(id = rep(1:5,3), 
             value = c(seq(50,58,2),seq(60,68,2),seq(70,78,2)),
             name = c(rep("A",5),rep("B",5),rep("C",5)),
             type = rep(c("a","b","c","d","r"),3))

df$name <- factor(df$name, levels = c("C","B","A"),ordered = TRUE)
ggplot(df, aes(id, value, fill = name,color = type))+
    geom_area( position = 'identity', linetype = 1, size = 1 ,colour="black") +
    geom_point(size = 8)+
    guides(fill = guide_legend(override.aes = list(colour = NULL, shape = NA)))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

jaz*_*rro 4

如果我正确地阅读了问题,那么您似乎只需要蓝色区域的点。在这种情况下,您可以对数据进行子集化并将其用于geom_point.

ggplot(df, aes(id, value, fill = name,color = type))+
geom_area( position = 'identity', linetype = 1, size = 1 ,colour="black") +
geom_point(data = subset(df, name == "A"), size = 8) +
guides(fill = guide_legend(override.aes = list(colour = NULL, shape = NA)))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述