How to change distance between rows on lollipop

Viewed 161

enter image description hereI want to decrease the distance between the rows on my lollipop graph. Does anyone know how I would do this? Any assistance is appreciated it.

df <- data.frame(
parameters = c("Posting written messages online", "Text messages", "Phone calls", 
"Online learning system", "Online video chat","Blackboard Collaborate"),
value = c(32,29, 19, 53, 51,26))
df %>%
ggplot(aes(x= parameters, y=value)) +
geom_segment( aes(x= parameters, xend= parameters, y=0, yend=value), 
            color="dodgerblue4", size=2) +
geom_point( color="darkorange2", size=4.2, alpha=0.9) +
geom_text(aes(label = paste0(value,"%")), hjust = -0.3, size=3.8,family="Arial") + 
expand_limits(y = 100)+
theme_light() +
coord_flip() +
theme(
plot.margin = margin(1, 1, 4, 1.1, "cm"),
panel.grid.major.y = element_blank(),
axis.text.y = element_text(color = 'black', , size = 12, hjust = 1),
panel.border = element_blank(),
axis.ticks.y = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
axis.text.x = element_blank(),
axis.title.x.bottom = element_blank()
)
1 Answers

Try this for reordering:

library(ggplot2)
#Code
df %>%
  ggplot(aes(x= reorder(parameters,value), y=value)) +
  geom_segment( aes(x= reorder(parameters,value), xend= parameters, y=0, yend=value), 
                color="dodgerblue4", size=2) +
  geom_point( color="darkorange2", size=4.2, alpha=0.9) +
  geom_text(aes(label = paste0(value,"%")), hjust = -0.3, size=3.8,family="Arial") + 
  expand_limits(y = 100)+
  theme_light() +
  coord_flip() +
  theme(
    plot.margin = margin(1, 1, 4, 1.1, "cm"),
    panel.grid.major.y = element_blank(),
    axis.text.y = element_text(color = 'black', , size = 12, hjust = 1),
    panel.border = element_blank(),
    axis.ticks.y = element_blank(),
    axis.ticks.x = element_blank(),
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    panel.grid.major.x = element_blank(),
    panel.grid.minor.x = element_blank(),
    panel.grid.minor.y = element_blank(),
    axis.text.x = element_blank(),
    axis.title.x.bottom = element_blank()
  )

Output:

enter image description here

Related