'Substituting X-axis ticks and text with percentile rank in ggplot
I am currently trying to reproduce the following graph: Plot to be replicated
What I am struggling with is substituting the x-axis ticks and text to be the percentile rank rather than the country ISO (essentially replicating the x-axis in the "Plot to be replicated").
I am currently at the stage in this image: Attempted Replication
I am using the following code:
ggplot(data, aes(x = x, y = y)) +
geom_errorbar(aes(ymax = Cup, ymin = Cdo)) +
labs(x = "Country ISO",
y = "Transparency Rating",
title = "Transparency Index with CI") +
theme_light() +
theme(panel.grid.major.x = element_blank() ,
panel.grid.major.y = element_line( size=.05, color="grey")
)
I tried to use the options with various inputs but I can seem to make it work:
theme(axis.ticks.x = ,
axis.text.x =)
)
Some data useful for your replication:
x<-c("AFG","ALB","ITA",
"IND","AGO","ARE",
"ATG","BEN","BFA",
"BGD","BGR","BHR",
"BHS","BIH","BRB",
"BRN","BTN","BWA",
"CAF","CAN")
y<-c(1:20)
Cup<-y+0.4
Cdo<-y-0.4
data<- data.frame(x,y,Cup,Cdo)
Extra points for those who can also tell me how to add certain specific country names at the right point inside of the plot like in the "Plot to be replicated".
Thank you so much for your help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
