Geom_text over the upper bound

Hi,

I wonder what shall I do so that the label over the bars 'fits' into the plot?

many thanks,

Jakiub

1 Like

change the scale of the yaxis to go to a higher number than 10; I would expect that to compress the visuals along that dimension. or maybe adjusting theme margins would work.

1 Like

Thank you. I'd like to keep the limits of the y-axis as they are.

Please provide a reprex

finis_long <-  structure(list(tercil_SS = c("do 200 žáků", "do 200 žáků", 
                             "mezi 200 a 400 žáky", "mezi 200 a 400 žáky", "nad 400 žáků", 
                             "nad 400 žáků"), zrizovatel = structure(c(2L, 1L, 2L, 1L, 
                                                                       2L, 1L), .Label = c("veřejné", "soukromé/církevní"), class = "factor"), 
               pomer = c(1.01037483130724, 1.59056222846675, 2.86757887013722, 
                         5.41665516204124, 5.19713582708909, 9.45677324152481), tercil = structure(c(1L, 
                                                                                                     1L, 2L, 2L, 3L, 3L), .Label = c("do 200 žáků", "mezi 200 a 400 žáky", 
                                                                                                                                     "nad 400 žáků"), class = "factor")), class = c("grouped_df", 
                                                                                                                                                                                    "tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L), groups = structure(list(
                                                                                                                                                                                      tercil_SS = c("do 200 žáků", "mezi 200 a 400 žáky", 
                                                                                                                                                                                                   "nad 400 žáků"), .rows = structure(list(1:2, 3:4, 5:6), ptype = integer(0), class = c("vctrs_list_of", 
                                                                                                                                                                                                                                                                                          "vctrs_vctr", "list"))), row.names = c(NA, -3L), class = c("tbl_df", 
library(ggplot2)                                                                                                                                                                                                                                                                                                                                          "tbl", "data.frame"), .drop = TRUE))


plot <- ggplot(finis_long, aes(x=tercil_SS, y=pomer, fill=tercil_SS,
                               label = scales::comma(pomer, accuracy = 1, scale = 1, prefix = "", suffix = "",
                                                     big.mark = " ", decimal.mark = ","))) +
  geom_col()+
  geom_text(aes(label=scales::comma(pomer, accuracy = 0.1,  decimal.mark = ","),
                vjust=-1))+
  scale_fill_manual(values=c("#F2CE6E", "#EF726B","#74496B", "#67A88F")) +
  theme_minimal() +
  theme(legend.position = 'none',
        legend.title = element_blank(),
        text = element_text(size=15),
        plot.title = element_text(margin=margin(0,0,15,0)),
        axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        panel.spacing = unit(2, "lines"),
        panel.grid.major.x = element_blank() 
  ) +
  scale_y_continuous(label=scales::comma_format(accuracy = 1, scale = 1, prefix = "", suffix = "",
                                                big.mark = " ", decimal.mark = ","),
                     limits = c(0,10)) +
  facet_grid(rows= vars(zrizovatel)) +
  ggtitle("Průměrný počet nepedagogických zaměstnanců v SŠ")
        
        
plot

You made an error in your copy and pasting.
library(ggplot2) got pasted within your dput() content of finis_long

also, it seems theres no issue, if you make the plot window nice and tall in your IDE

thank you very much!

I usually export images at 700x450 pixels. Do you have any idea how to make the label completelly visible for this case?

many thanks again,

J

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.