Home > other >  Specify a line break in a csv that translates to read.csv() in R
Specify a line break in a csv that translates to read.csv() in R

Time:01-17

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).

enter image description here

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:

enter image description here

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

enter image description here

CodePudding user response:

For the csv use gsub("\\n", "\n", State, fixed = TRUE) to correct the response listed above

  • Related