R语言 相同y值的多个点

5lwkijsr  于 2023-02-06  发布在  其他
关注(0)|答案(2)|浏览(120)

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()

我想为CPI指数数据绘制一个棒棒糖图,每个国家都有三个类别,如何显示这些类别,使它们不重叠
我想为CPI指数数据绘制一个棒棒糖图,每个国家都有三个类别,如何显示这些类别,使它们不重叠

vuktfyat

vuktfyat1#

您可以将position_dodgecoord_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()

laawzig2

laawzig22#

大概是这样的

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()

相关问题