Home > database >  Multiple points for same y-value
Multiple points for same y-value

Time:02-05

image for reference

library(ggplot2)
df <- read.csv("Counsumer_Price_Index.csv")


sav <- df %>%
  filter(ï..Location %in% c("IRL", "CAN", "AUS",
                            "USA", "FRA", "DEU",
                            "ESP", "ITA")) %>%
  filter(Time == 2021) %>%
  filter(Subject != "Energy")
sav


sav %>% ggplot(aes(x = Percentage, y = ï..Location))  
  geom_point(aes(colour = Subject), size = 2.5)   
  geom_segment(aes(yend = ï..Location, colour = Subject), xend = 0 , linetype="dotted")   theme_light()

I want to make a lollipop plot for the CPI index data, for each country there are three categories how do I display the categories such that they dont overlap

I want to make a lollipop plot for the CPI index data, for each country there are three categories how do I display the categories such that they dont overlap

CodePudding user response:

You could use position_dodge with a coord_flip:

library(ggplot2)

sav %>% 
  ggplot(aes(x = ï..Location, y = Percentage, colour = Subject))  
  geom_point(size = 2.5, position = position_dodge(0.5))   
  geom_linerange(aes(ymin = 0, ymax = Percentage),
               linetype = "dotted", position = position_dodge(0.5))   
  coord_flip()  
  theme_light()

enter image description here

CodePudding user response:

Something like this:

library(ggplot2)

sav %>% ggplot(aes(x = Percentage, y = ï..Location))  
  geom_point(aes(colour = Subject), size = 2.5)   
  geom_segment(aes(yend = ï..Location, colour = Subject), xend = 0 , linetype="dotted")   
  facet_wrap(. ~ Subject)  
  theme_light()

enter image description here

  • Related