Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Plot different variables on different graphs on top of each other

$
0
0

I have 3 different variables (A, B, C) to be plotted on 3 graphs on top of each other(as they have different axis). My output has a lot of space between graphs and I would like to reduce that space and have an only X-Axis at the bottom and wider graph y-limits on all.

I have also read maybe facet_wrap is a better way of plotting multiple graphs? Could you please give me advice on what is best to do? Thanks

My data:

Location = c(1,2,3,4,5,6,7)
A = c(1.16, 0.96, 0.67,0.78, 0.55, 0.3,0.26)
B = c(6.51, 4.98, 2.85, 3.19, 3.60, 10.82, 8.60)
C = c(75.45, 86.66, 103.36, NA, 107.53, NA, 128.49)

df = data.frame(Location, A, B, C)

My code:

par(mfrow=c(3,1))

plot(A, type = "l", col = "red", ylab = "A", main="Title", xlab = NULL)
plot(B, type = "l", col = "Blue", ylab = "B", xlab = NULL)
plot(C, type = "p", pch= 19, col = "Blue", ylab = "C", xlab = Location)

enter image description here


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>