I am trying to add a geom_label that has a line break and I can't figure out what I am doing wrong. First I am saving my csv with the line breaks (see below).
then I am just using read.csv()
and it gives me data like this:
structure(list(State = "Alabama\\n(regulation change)", Year = 2019.666667,
position = 35L), row.names = 1L, class = "data.frame")
This is my code:
library (ggplot2)
ggplot(data,aes(x=Year))
geom_label(aes(y=position,label=State))
This is my plot:
Why is it not printing a linebreak at \n
?
CodePudding user response:
I believe \n is working , as @stefan suggested please replace \\n with \n
CodePudding user response:
For the csv use gsub("\\n", "\n", State, fixed = TRUE)
to correct the response listed above