Havign issues with ggplot

Hi guys,
I'm totally new to R. I'm trying to create a ggplot.

This is the code I am using right now:

ggplot(data = Mittel_tab, aes(y=Beschriftung_links))+
  geom_point(aes(x=Registerkasse),size=4,color="grey35")+theme_bw()+theme(panel.grid = element_blank(), panel.grid.major.y = element_line(color = "grey",linetype = "dotted"))+
  geom_point(aes(x=ScanGo),size=4,color="lightsalmon")+theme_bw()+theme(panel.grid = element_blank(), panel.grid.major.y = element_line(color = "grey",linetype = "dotted"))+
  labs(x="",y="",title = "Wie empfinden Sie den herkömmlichen Kassiervorgang/ Scan & Go im LEH?")+ theme(plot.title = element_text(hjust=0.5,size = 9, face = "bold"))+
  xlim (0,101)

So far this works quite good but I have to add a second axis on the right side (Because it is contrasting pair, the negative one at the left and the positive one on right, for example inefficient and efficient). Also I like to add a legend for the colors and connecting lines between the dots.

In the end it should look like this ( I marked the missing data in red):

Thanks for any help!!

Could yo post your data? You can use the output of


structure(list(Beschriftung links = c("Ineffizient", "Hektisch",
"Nicht kundenfreundlich", "Altmodisch", "Stressig", "Unzureichend"
), ScanGo = c(71.6376811594203, 69, 64.1618357487923, 85.1884057971015,
66.8164251207729, 70.2826086956522), Registerkasse = c(48.9347826086956,
32.6304347826087, 55.7850241545894, 33.5893719806763, 37.0917874396135,
54.8599033816425), Beschriftung rechts = c("Effizient", "Gelassen",
"Kundenfreundlich", "Innovativ", "Angenehm", "Zufriedenstellend"
)), class = "data.frame", row.names = c(NA, -6L))

I was going to respond that this is not possible with ggplot2 because secondary axes are not defined for discrete axes.

However, if the axes are artificially converted to continuous. then this really hacky method works:


Mittel_tab %>% 
  mutate(dummy = 1:nrow(Mittel_tab)) %>% 
  pivot_longer(c(ScanGo, Registerkasse)) %>% 
  ggplot(aes(dummy, value, colour = name)) + 
  geom_point() + 
  geom_line() + 
  coord_flip() + 
    breaks = 1:nrow(Mittel_tab), 
    labels = Mittel_tab$Beschriftung_links, 
    sec.axis = dup_axis(
      labels = Mittel_tab$Beschriftung_rechts
  ) + 
  scale_y_continuous(limits = c(0, 100)) + 
    title = "Wie empfinden Sie den herkömmlichen Kassiervorgang/ Scan & Go im LEH?", 
    x = NULL, 
    y = NULL, 
    colour = NULL

I doubt I would recommend it though.

Thank you for your quick response!

I don't know what I am doing wrong. I just copied the code (yes, the package is installed), but the contrasting pairs still do not appear in the ggplot.

This is what it looks right now:

What's the output of glimpse(Mittel_tab)?

Rows: 6
Columns: 4
`Beschriftung links` <chr> "Ineffizient", "Hektisch", "Nicht kundenfreundlich", "Altmo… ScanGo 71.63768, 69.00000, 64.16184, 85.18841, 66.81643, 70.28261
Registerkasse <dbl> 48.93478, 32.63043, 55.78502, 33.58937, 37.09179, 54.85990 Beschriftung rechts "Effizient", "Gelassen", "Kundenfreundlich", "Innovativ", "…

One issue may be the naming of the columns.

If you include spaces in columns (or any other objects) they must be surrounded by tick marks ``, but you will make life easier by avoiding this and renaming these using e.g. an underscore _.

If this does not fix things, the please include a reprex:
FAQ: How to do a minimal reproducible example ( reprex ) for beginners - meta / Guides & FAQs - RStudio Community

Oh yes, now it works.
Thank you so much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.