ggplot 几何点和几何段的颜色问题

color issue with ggplot geom point and geom segment

我正在尝试根据以下 R 数据框绘制一个简单的图。我复制了以下数据框的 dput 输出:

structure(list(troponin.cat = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15), percentage = c(0, 13, 29, 40, 47, 53, 
57, 60, 62, 65, 66, 67, 69, 70, 71, 78)), .Names = c("troponin.cat", 
"percentage"), row.names = c("0", "1", "2", "3", "4", "5", "6", 
"7", "8", "9", "10", "11", "12", "13", "14", "15+"), class = "data.frame")

我的剧情代码是

plot.2 <- ggplot(data=cumsum, aes(x=troponin.cat, y=percentage))+
geom_point(colour="red", size=5)+
geom_segment(aes(yend = 0, xend = troponin.cat, colour="red", size=5))+
scale_x_continuous(breaks=seq(1, 15, 1))+
geom_line(colour="red")+
theme_classic()

由于某些原因,geom 点的颜色与 geom 段不同,我不知道为什么??

这是您想要实现的目标吗?

library(ggplot2)

dat <- structure(list(troponin.cat = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15), percentage = c(0, 13, 29, 40, 47, 53, 
57, 60, 62, 65, 66, 67, 69, 70, 71, 78)), .Names = c("troponin.cat", 
"percentage"), row.names = c("0", "1", "2", "3", "4", "5", "6", 
"7", "8", "9", "10", "11", "12", "13", "14", "15+"), class = "data.frame")

plot.2 <- ggplot(data=dat, aes(x=troponin.cat, y=percentage))+
  geom_segment(yend=0, aes(xend=troponin.cat), colour="#a50f15", size=5) +
  geom_point(colour="#a50f15", size=5) +
  geom_line(colour="#a50f15") +
  scale_x_continuous(breaks=seq(1, 15, 1)) +
  theme_classic()

plot.2