Could you help me to build horizontal dots plot via using this code given on this
CodePudding user response:
You can get pretty close to the target image like this:
library(ggplot2)
ggplot(df, aes(x = rate, y = factor(origin, rev(origin))))
geom_hline(aes(yintercept = origin), color = 'gray')
geom_vline(xintercept = 0, linetype = 2, color = 'gray')
geom_point(aes(color = 'Rate'), size = 10)
geom_text(aes(label = rate), color = 'white')
geom_point(aes(x = change, color = 'Change'), size = 10)
geom_text(aes(label = change, x = change))
theme_minimal(base_size = 16)
scale_x_continuous(labels = ~paste0(.x, '%'), name = NULL)
scale_color_manual(values = c('#aac7c4', '#5f9299'))
theme(panel.grid = element_blank(),
axis.text.y = element_text(color = 'gray50'))
labs(color = NULL, y = NULL)