Kalle Kalle - 8 months ago 69
R Question

R Scatterplot, transform values used as label

I have a simple dataframe and produce a scatterplot:

a <- c(-1,-2,-1.5)
b <- c(1,3,2)
df <- data.frame(a,b)
plot(a , b)

enter image description here

I would like to remove the minus signs before the x-axis labels, i.e. multiply the labels by -1.

Is a way to do that or do I have to create another column in the data frame for the labels?



plot(a, b, xaxt = "n")
pos <- axTicks(1)
axis(1, at = pos, labels = abs(pos))

enter image description here