Data
X: 45, 20, 32, 45
Y: 10, 27, 10, 6
P: 0.758, 0.126, 0.068, 0.493,
I want to change the hexbin "count" gradient scale on the right to the variable "P" in the data. Is this possible? If so how with the code I am using:
> ggplot(SLOAN,aes(x=Xpos,y=Ypos)) + stat_binhex(bins = 25, colour ="grey", alpha = 0.7) + scale_fill_gradientn(colours = c("yellow","orange","red")) +
+ guides(alpha = FALSE, size = FALSE) + xlim(0,50) + ylim(0,47) + geom_rug(alpha = 0.2) +
+ coord_fixed()
You could use stat_summary_hex()
library(ggplot2)
SLOAN <- data.frame(
Xpos = c(45, 20, 32, 45),
Ypos = c(10, 27, 10, 6),
P = c(0.758, 0.126, 0.068, 0.493)
)
ggplot(SLOAN,aes(x=Xpos,y=Ypos, z = P)) +
stat_summary_hex(colour ="grey", alpha = 0.7) +
scale_fill_gradientn(colours = c("yellow","orange","red")) +
xlim(0, 50) +
ylim(0, 47) +
geom_rug(alpha = 0.2) +
coord_fixed()
Created on 2019-12-11 by the reprex package (v0.3.0.9000)
Thank you! Do you know if there is a way to smooth the hex bins so they are not as defined?
Your description is a little vague, do you have a reference image so we can have a better idea of what you are looking for?
See how this picture is smooth? I want my graph to look like this but with color.
That graph is done with smooth.hexbin
Sorry but I fail to see how is smoother, I just can see a fill gradient on grayscale without borders, try with less saturated colors for your fill scale and take out the borders.
library(ggplot2)
SLOAN <- data.frame(
Xpos = c(45, 20, 32, 45),
Ypos = c(10, 27, 10, 6),
P = c(0.758, 0.126, 0.068, 0.493)
)
ggplot(SLOAN,aes(x=Xpos,y=Ypos, z = P)) +
stat_summary_hex() +
scale_fill_gradient(low = "#FFFF0064", high = "#F02B2B70") +
xlim(0, 50) +
ylim(0, 47) +
geom_rug(alpha = 0.2) +
theme_minimal() +
theme(panel.grid = element_blank()) +
coord_fixed()
Is there a way to add color to the Hex bin smooth graph? I also want to make the gradient scale the value of P, not "count." Any ideas on how to help? Thank you!
A= 7, 47,10, 26, 6
B= 13, 6, 18, 20, 4
P= 0.495, 0.511, 0.533, 0.097, 0.499
bin<-hexbin(A,B)
smbin <- smooth.hexbin(bin)
plot(smbin, main = "smooth.hexbin(.)")
system
Closed
January 2, 2020, 6:25am
8
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.