简体   繁体   中英

How can I define a color palette (normalize) for multiple hexbin plots in R

I want to find a way to set a certain range of a color palette that is used for a hexbin plot to normalize multiple plots in R.

So far I have tried:

library(hexbin)
library(gplots)  
my.colors <- function (n)
{
    (rich.colors(n))
}
plot(hexbin(lastthousand$V4, lastthousand$V5, xbnds=c(0,35), ybnds=c(0,35),), xlab="Green Pucks", ylab="Red Pucks",colramp = my.colors, colorcut = seq(0, 1, length = 25),lcex=0.66)

Which results in the follwing plot: hexbin plot #1 I understand that "colourcut" controls the resolution of the color palette. But I found no way to controll the min/max values

Lets say I have a second plot - 'hexbin plot #2' - with counts from 1(dark-blue) to 100(red). Is there a way to use only the colors 1(dark-blue)-24(light-blue) [based on only a part of the 1(dark-blue)-100(red) scale] for hexbin plot #1?

The final goal is to have several hexbin plots next to each other which follow the same colour scheme (min and max based on the one with the highest counts).

-this is my first question here :) and I'm new to R, please be gentle //edit: For everyone with the same problem: My supervisor suggested to use facets in ggplot2. Will see how that works and return with another edit if it solves the issue.

//edit2: factes did the trick:

library(gplots)  
library(ggplot2)
p <- ggplot(data=lastthousand, aes(lastthousand$V4,lastthousand$V5))+ geom_hex()
p + facet_grid(. ~ Market) + xlab("green pucks") + ylab("red pucks") + scale_colour_gradientn(colours=rainbow(7))

Facets does the trick:

library(gplots)  
library(ggplot2)

p <- ggplot(data=lastthousand, aes(lastthousand$V4,lastthousand$V5))+ geom_hex()
p + facet_grid(. ~ Market) + xlab("green pucks") + ylab("red pucks") + scale_colour_gradientn(colours=rainbow(7))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM