ggplot geom point和geom segment的颜色问题

时间:2015-02-01 15:58:21

标签: r plot

我试图从下面的R数据框中制作一个简单的图。我复制了以下数据框的输出输出:

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段不同,我不明白为什么??

1 个答案:

答案 0 :(得分:0)

这是你想要达到的目标吗?

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

enter image description here