-1

I am trying to replicate the bar plot as shown bellow.

Here is an example of the data frame. Where the y variable is tasa and the x variable is year, and the number showed in the text of each x tick label is inscripciones.

df <- structure(list(year = c("2018", "2019"), inscripciones = c(3038910, 3680696), tasa = c(88.9528707645112, 104.692208214133)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -2L))

p <- ggplot(data = df, aes(x = year, y = tasa)) +
  geom_bar(width = 0.4, stat = "identity", fill="orange")+
  geom_text(aes(year, tasa + 5, label = round(tasa,2), fill = NULL), size=4)+
  labs(x = NULL, y = NULL)+
  scale_y_continuous(breaks = seq(0, 110, by = 10))+
  theme_bw() 

How can I add these long text including information from the dataframe to the x tick labels?

Graph

user2246905
  • 1,029
  • 1
  • 12
  • 31

1 Answers1

1

Firstly, your data & plot combination are not reproducible. I renamed annoh as year then create the plot p.

Then,scale_x_discrete with "\n" strings works when you want to skip lines;

enter image description here

long_text_1 <-  'Gün, senden ışık alsa\n da bir renge bürünse;\n
Ay, secde edip çehrene,\n yerlerde sürünse;\n
Her şey silinip\n kayboluyorken nazarımdan,\n
Yalnız o yeşil\n gözlerinin nuru görünse...'

long_text_2 <- 'Ruhun mu ateş,\nyoksa o gözler mi alevden?\n
Bilmem bu yanardağ\n ne biçim korla tutuştu?\n
Pervane olan kendini\n gizler mi hiç alevden?\n
Sen istedin ondan bu\n gönül zorla tutuştu.'


p <- ggplot(data = df, aes(x = year, y = tasa)) +
  geom_bar(width = 0.4, stat = "identity", fill="orange")+
  geom_text(aes(year, tasa + 5, label = round(tasa,2), fill = NULL), size=4)+
  labs(x = NULL, y = NULL)+
  scale_y_continuous(breaks = seq(0, 110, by = 10))+
  theme_bw()+
  scale_x_discrete(labels=c('2018'=long_text_1,'2019'=long_text_2))
Samet Sökel
  • 2,515
  • 6
  • 21