R flip the XY axis on the plot

This seems like a trivial matter R, but I have not found a convincing solution. I would like to flip my plot where the X axis will become Y, and vice versa. There is an option in boxplot horiz="T", but not in plot().

Here is what I draw:

plot(rm, type="l", main="CpG - running window 100")

> str(rm)
 num [1:43631] 0.667 0.673 0.679 0.685 0.691 ...

This is what I have

And I would like to get the following:

enter image description here

Thanks for the feedback.

+5
source share
1 answer

I think the problem is that there is clearly no index in the plot. Try the following:

set.seed(1)
a = rnorm(200) # like your `rm` -- bad name for an object, by the way
plot(a, type="l", main="rnorm(200)") # index automatically added

This is similar to what you have. It is also equivalent plot(1:length(a), a, ...)where 1:length(a)- your xand a- yours y.

enter image description here

With this in mind, we can flip the chart as follows:

# index specified, and X-Y swapped
plot(a, 1:length(a), type="l", main="rnorm(200)") 

enter image description here

+3
source

All Articles