R 如何分类和标注棒棒糖图表

R 如何分类和标注棒棒糖图表,r,ggplot2,R,Ggplot2,我有一个棒棒糖图,我想改变酒吧降序,并添加数据标签。有人知道我会怎么做吗? 我的数据在这里 条形图的顺序由状态的因子级别控制,添加数据标签可由geom_text管理 library(dplyr) library(ggplot2) states %>% arrange(count) %>% mutate(state = factor(state, unique(state))) %>% ggplot() + aes(x=state, y=count) + geo

我有一个棒棒糖图,我想改变酒吧降序,并添加数据标签。有人知道我会怎么做吗? 我的数据在这里


条形图的顺序由状态的因子级别控制,添加数据标签可由
geom_text
管理

library(dplyr)
library(ggplot2)

states %>%
  arrange(count) %>%
  mutate(state = factor(state, unique(state))) %>%
  ggplot() + aes(x=state, y=count) +
  geom_segment( aes(x=state, xend=state, y=0, yend=count), color="dodgerblue4") +
  geom_point( color="dodgerblue4", size=4, alpha=0.6) +
  geom_text(aes(label = count), hjust = -1) + 
  theme_light() +
  coord_flip() +
  theme(
    panel.grid.major.y = element_blank(),
    panel.border = element_blank(),
    axis.ticks.y = element_blank()
  )

谢谢。这太完美了。我还有最后一个问题。是否可以将状态名称的字体颜色更改为黑色?您可以在
主题中添加
axis.text.y=element\u text(颜色='black')
library(dplyr)
library(ggplot2)

states %>%
  arrange(count) %>%
  mutate(state = factor(state, unique(state))) %>%
  ggplot() + aes(x=state, y=count) +
  geom_segment( aes(x=state, xend=state, y=0, yend=count), color="dodgerblue4") +
  geom_point( color="dodgerblue4", size=4, alpha=0.6) +
  geom_text(aes(label = count), hjust = -1) + 
  theme_light() +
  coord_flip() +
  theme(
    panel.grid.major.y = element_blank(),
    panel.border = element_blank(),
    axis.ticks.y = element_blank()
  )