Keep the same scale across ggplot2 graphs

I want to create 3 graphs in ggplot2 as follows:

ggplot(observbest,aes(x=factor(iteration),y=bottles,colour=Team ,group=Team)) + geom_line() + scale_colour_gradientn(colours=rainbow(16)) 
ggplot(observmedium,aes(x=factor(iteration),y=bottles,colour=Team ,group=Team)) + geom_line() + scale_colour_gradientn(colours=rainbow(16))
ggplot(observweak,aes(x=factor(iteration),y=bottles,colour=Team ,group=Team)) + geom_line() + scale_colour_gradientn(colours=rainbow(16))

That is, three graphs display the same thing, but for a difference data set each time. I want to compare them, so I want their y axis to be snapped to the same scale with the same fields on all graphs, which is not happening automatically now.

Any suggestion?

thank

+2
source share
3 answers

It seems that facet_wrapby all the observations combined into a single block of data, it may be what you are looking for. For instance.

library(plyr)
library(ggplot2)

observ <- rbind(
  mutate(observbest, category = "best"),
  mutate(observmedium, category = "medium"),
  mutate(observweak, category = "weak")
)

qplot(iteration, bottles, data = observ, geom = "line") + facet_wrap(~category)

enter image description here

+4
source

Add + ylim(min_value,max_value)to each chart.

, , , , linetype .

+2

Use scale_y_continuousto determine the y axis for each graph and make them easily comparable.

+1
source

Source: https://habr.com/ru/post/1691807/


All Articles