0

Here's my initial barchart code:

Full %>%                  ggplot(aes(x = reorder(POS, -Iconicity), y = Iconicity, fill = Group)) +
  geom_bar(stat = "summary", position=position_dodge(width = 0.9)) +
    scale_fill_viridis_d() + # color-blind compatible colors
  theme_minimal() + xlab("POS")

Which creates this lovely chart:

the barchart

So I wanted to turn this into a lollipop chart to make it look neater and more modern, and this is the code I used:

Full %>%                  ggplot(aes(x = reorder(POS, -Iconicity), y = Iconicity, color = Group)) +
  geom_point(size=3, stat = "summary", position=position_dodge(width = 0.9)) +
  geom_segment(aes(x=POS, 
                    xend=POS, 
                    y=0,
                    yend=Iconicity)) +
  scale_fill_viridis_d() + # color-blind compatible colors
  theme_minimal() + xlab("POS") 

However of course that does not add enough segments to the right places and I can't seem to work out how to change to code. What I'm left with is this:

catastrophic lollipop chart attempt

I'm still quite a novice at R clearly so forgive me

Md. Ahsan
  • 23
  • 1
  • 4
  • 1
    could you explain a little bit more about what you want the final figure to look like - 'lollipop chart ' is a little big vague. Could you also please use the dput() function to show us what your data looks like. thanks. – user438383 Apr 09 '20 at 22:31

1 Answers1

1

I think the issue is coming from the fact you summarise your geom_point and not geom_segment and you are using position_dodge in geom_point.

Without a reproducible example of what is Full, it is hard to be sure of the answer to your question, but maybe you can try to summarise your values outside of ggplot and apply the same position_dodge to every geom:

Full %>%  
  group_by(Group) %>%
  summarise(Iconicity = mean(Iconicity, na.rm = TRUE)) %>%
  ggplot(aes(x = reorder(POS, -Iconicity), y = Iconicity, color = Group)) +
  geom_point(size=3,position=position_dodge(width = 0.9)) +
  geom_segment(aes(x=POS, 
                   xend=POS, 
                   y=0,
                   yend=Iconicity), position = position_dodge(0.9) ) +
  scale_fill_viridis_d() + # color-blind compatible colors
  theme_minimal() + xlab("POS") 

Does it answer your question ?

If not, please provide a reproducible example of what is your Full Dataset (see this link: How to make a great R reproducible example)

dc37
  • 15,840
  • 4
  • 15
  • 32