plot(x,y,type="h",...)
text(x,y,labels=columnL)
This seems very simple: I have a (histogram) plot and use the text function to label the points.
In the data table, I have rows containing the x, y and label names (columnL, each point has a different name). The table is imported via read.table from a .csv file.
Everything works fine, BUT: I want to use subscript and superscript in the labels, and all solutions I found were for axis labels - here, I have a range of different labels, all of which need to be formatted correctly, so I was not successful when trying paste()
and expression()
in the text(labels=)
(returned the same label for all points)... So, more generally: is it possible to have formatting options in these labels?
I am completely new to R (and programming), sorry if this is unclear or seems stupid. There is probably a way to "batch handle" the content of ColumnL somehow. I could add the formatting ([] and ^) to the .csv file ahead of time (but because it is not read as expression the output has no formatting).
UPDATED Edit: This almost works:
mytable <- read.table("C:/Data/Example.txt", header= T, sep= "\t")
attach(mytable)
ColL <- as.character(ColumnL)
ColN <- parse(text=ColL)
plot(x1,y1)
text(x1,y1+0.1,labels=ColN)
where Example.txt contains:
x1 y1 ColumnL
1 2 a[1]^"+"
1 3 b[19]
2 5 c[27]
4 6 v[45]
What's good about this is that the subscript works for the numbers (and I don't mind having the formatting defined in the input file). However, the one thing that I can't fix is that the "+"
, regardless of quotes, triggers a concatenation of rows 1 and 2 when ColL
is run through parse()
. How can I properly use +
here? It is supposed to be superscript...
Edit:
Note that the problem only occurs when "+"
is the last (non-space) character of the entry (or when followed by [), otherwise it works fine (apparently "+"
is only supposed to be in equations and there you wouldn't expect it at the end, but that's where I need it)