r - ggplot2 tile scale limits -
this question has answer here:
apologies if bit of obvious question, can tell me how can set scale on heatmap drawn geom tile? want draw several heatmaps on same scale (e.g. drawn colours scaled maximum of 10 though on 2 of them maximum 5) , can't work out.
an example:
mydata<-expand.grid(x1=1:8,y1=1:5) z1<-floor(runif(40,min=0,max=6)) z2<-floor(runif(40,min=0,max=11)) mydata<-cbind(mydata,z1,z2) mydata<-data.frame(mydata) p1 <- ggplot(mydata, aes(x=x1, y=y1, z = z1)) p1 <- p +geom_tile(aes(fill = z1)) p2 <- ggplot(mydata, aes(x=x1, y=y1, z = z2)) p2 <- p +geom_tile(aes(fill = z2))
p1 scaled between 0 , 4 whereas p2 scaled between 0 , 10. i'd draw both of them colours on same scale - "4" has same colour in both heatmaps.
thanks help
sorry misread question first time round - how this?
colors<-c("red","orangered","orange","yellow","lightyellow", "lightgreen","green","darkgreen","darkblue","purple") df<-expand.grid(x=1:5,y=1:5,grp=1:4) # fill in 4 grids df$vals<-runif(100)*10 # add values between 0 & 10 ggplot(df) + geom_tile(aes(x,y,fill=vals)) + facet_wrap(~ grp) + scale_fill_gradientn(colours=colors,values=1:10,rescaler = function(x,...) x, oob = identity)
# , filtering out high numbers groups ggplot(df[df$vals<=5|df$grp<3,]) + geom_tile(aes(x,y,fill=vals)) + facet_wrap(~ grp) + scale_fill_gradientn(colours=colors,values=1:10,rescaler = function(x,...) x, oob = identity)
Comments
Post a Comment