如何删除折线图(几何图形线)R ggplot2上的点?

如何删除折线图(几何图形线)R ggplot2上的点?,r,ggplot2,R,Ggplot2,我是新手,我需要你的帮助。我需要从多条线geom_线中删除点编号8,x=“180”,但保留在geom_点。你该怎么办 数据在excel电子表格中 data<-melt(CB_fechado, id.vars = 'a'); #Ângulo de incidência de vento #print(data) Grafico_CB_fechado <- ggplot(data,aes(x =`Ângulo de incidência de vento [°]`, y=`value`

我是新手,我需要你的帮助。我需要从多条线geom_线中删除点编号8,x=“180”,但保留在geom_点。你该怎么办

数据在excel电子表格中

data<-melt(CB_fechado, id.vars = 'a');
#Ângulo de incidência de vento
#print(data)

Grafico_CB_fechado <- ggplot(data,aes(x =`Ângulo de incidência de vento [°]`, y=`value`, color=`variable`))+
geom_line() + geom_point()+ 
scale_x_continuous(limits = c(0,180), breaks = c(0,15,30,45,60,75,90,105,120,135,150,165,180))+
scale_y_continuous(limits = c(-1.5,1.5))+ 
ylab("b")+theme(legend.position = "bottom")+
theme(legend.title = element_blank())


data这是关于对用于
geom_line()
的数据进行子集设置。并不是说,如果不是最后一点,这会有点复杂。这是一个具有类似虚拟数据的示例,因为我不想从图像中键入

虚拟数据

data <- data.frame(angle = rep(c(0:6*15, 180), 4),
                   cat = rep(LETTERS[1:4], each = 8),
                   value = rep(1:4/-4, each = 8))

诀窍是在
ggplot
调用中使用数据的子集。在这种情况下,我使用
subset
删除
a=180的点
注意,我将color参数重新定义为“red”

数据。

data <- read.table(text = "
    a       b
1   0   0.57395085
2   15  0.47593420
3   30  0.30175686
4   45  0.13363012
5   60  -0.02727459
6   75  -0.17971621
7   90  -0.44955122
8   180 -0.30247414
", header = TRUE)

新案例多行数据?@FelipeOliveira如果按
color=variable
分组,则应自动分组。在我的代码中更改它,没有
color=“red”
。对于新案例,多行?我认为它应该可以工作。您也可以执行
data[-8,]
或更具体的点理解操作,但数据变量仅消除了一行180º,而没有消除另一行。应该消除-8、-16、-24。。你会怎么做?好吧,我想我明白了。我编辑了我认为你们想要做的,但有代表性的虚拟数据。@Adam非常感谢!!这让我很头痛。这正是我所需要的。
library(ggplot2)

ggplot(data, aes(x = angle, y = value, color= cat)) +
  geom_line(data = data_lines) +
  geom_point()+ 
  scale_x_continuous(limits = c(0,180), breaks = c(0,15,30,45,60,75,90,105,120,135,150,165,180))+
  scale_y_continuous(limits = c(-1.5,1.5))+ 
  ylab("b")+theme(legend.position = "bottom")+
  theme(legend.title = element_blank())
library(ggplot2)

ggplot(data, aes(x = a, y = b, color = "red")) +
  geom_point()+ 
  geom_line(data = subset(data, a != 180)) + 
  scale_x_continuous(limits = c(0,180), breaks = c(0,15,30,45,60,75,90,105,120,135,150,165,180))+
  scale_y_continuous(limits = c(-1.5,1.5))+ 
  ylab("b") +
  theme(legend.position = "bottom",
        legend.title = element_blank())
data <- read.table(text = "
    a       b
1   0   0.57395085
2   15  0.47593420
3   30  0.30175686
4   45  0.13363012
5   60  -0.02727459
6   75  -0.17971621
7   90  -0.44955122
8   180 -0.30247414
", header = TRUE)