如何创建棒棒糖图

时间:2019-05-15 12:10:35

标签: r ggplot2

我正在尝试创建基本的棒棒糖图并遇到问题。我修改了一些旧代码,这些代码可以在另一个数据集上创建棒棒糖图,但是在我的新数据集上效果不佳。

cms<-subset(centuryscoresletters, school=='CMS') 
ggplot(data=cms, aes(x=id, y=mone)) 
geom_segment( aes(x=id, xend=id, y=0, yend=mone)) +
geom_point( size=3, color="red", fill=alpha("red", 0.3), 
          alpha=0.7, shape=16, stroke=1) + #shape=15 square, 8=star#
theme_light()  #code down here adjusts the background grid#
theme(
panel.grid.major.x = element_blank(),
panel.border = element_blank(),
axis.ticks.x = element_blank()
) +
xlab("") +
ylab("Value of Y")

link to dataset file

1 个答案:

答案 0 :(得分:2)

可以这样吗?

library(tidyverse)

data("anscombe")

anscombe %>%
  ggplot(aes(x = x1, y = y1, xend = x1, yend = 0)) +
  geom_segment(colour = "pink", size = 2) +
  geom_point(size = 15, colour = "orange") +
  #ggthemes::theme_few() +
  labs(x = "", y = "Value of Y")

enter image description here