I have next csv file:
x,y,label
2,3,A
3,4,C\n2
4,5,B
"\n" in the csv file means a second line. But, when I import this file, R replace "\n" with "\\n". And when use ggplot, generates a graph without a second line:
library(ggplot2)
data <- read.csv("text.txt")
ggplot(data = data, aes(x=x, y=y)) +
geom_text(aes(label = label))
I tried to use data$label <- gsub("\\\\", "\\", data$label) but replace "C\n2" to "Cn2".
I tried to use cat inside to geom_text: label = cat(label). But return error.
I can modified manually with data$label[2] <- "C\n2":
data$label[2] <- "C\n2"
ggplot(data = data, aes(x=x, y=y)) +
geom_text(aes(label = label))
but it requires automating for a larger amount of data.
How can I keep "\n"?


