I have the following df
my.data <- read.table(text = '
Porcentaje
Variable1 0.6
Variable2 0.4
Variable3 0.23
Variable4 0.19
Variable5 0.10
Variable6 0.04
Variable7 0.0
Variable8 0.0
', header = TRUE, stringsAsFactors = FALSE, na.strings = 'NA')
And I want to make the following graph:
ggplot(my.data ,aes( reorder(rownames(my.data ), Porcentaje),Porcentaje)) +
geom_col(fill="steelblue") + coord_flip(expand = FALSE)+
ggtitle ("Porcentaje de valores desconocidos")+
theme(plot.title = element_text(hjust = 0.5))+
xlab("Variables") + ylab("Porcentaje")
I would like the first bar to not go as far to the end of the chart, but rather to have more margin, i.e. widen the x-axis. I've tried with xlim but I can't.
You can let it
ggplot
adjust the margins by:But you could also adjust this expansion manually by adding:
Note that you have "flipped" the axes, and what you see as
x
actually being the axisy
, you can then also adjust the scale manually:O well: