0

I am trying to create a basic lollipop graph and running into issues. I modified some old code that worked to create a lollipop graph on another dataset, but it's not working well on my new dataset.

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

camille
  • 16,432
  • 18
  • 38
  • 60
freeazabird
  • 347
  • 2
  • 11
  • 1
    Hii, it would be useful to help you, if you share some kind of data set in order to reproduce your code. – Scipione Sarlo May 15 '19 at 12:12
  • Thanks, I just added a link to the dataset. – freeazabird May 15 '19 at 12:24
  • 6
    freeazabird, in case you don't get much response, it is common to balk at "links to datasets", for two reasons: (1) links go stale, and when that happens this question becomes unreproducible; (2) some, including myself, are unwilling to click on external links that might include nefarious "things". It seems unlikely on SO, but it's "unlikely" until it happens, then it's "highly annoying". – r2evans May 15 '19 at 12:45
  • 2
    It's preferred to include the output from `dput(head(x))` using as many rows as required to produce something meaningful; not a lot, not too little. – r2evans May 15 '19 at 12:45
  • 1
    "but it's not working well on my new dataset" How so? What do you expect to happen, and what do you get? "Working well" is subjective, and we don't have your output. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R example that's easy to help with – camille May 15 '19 at 12:56
  • (The answer currently provided does another common -- and often superior -- technique of using a publicly-available dataset.) – r2evans May 15 '19 at 12:56

1 Answers1

2

Might it be this way?

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

utubun
  • 4,400
  • 1
  • 14
  • 17
  • 1
    Just for code-reduction, do you need `select(x1,y1)`? (This looks good otherwise, just curious about the minimum code required to support the question. Nice use of the external dataset.) – r2evans May 15 '19 at 13:07
  • 1
    @r2evans Thank you ). This data set is famous, couldn't miss the opportunity to use it. You are absolutely right about the `select` statement (that was some initial thought I forgot of), I don't really need it. I am going to update the answer. – utubun May 15 '19 at 13:15