I have the following code to create a polar plot with ggplot2
but I am not be able to maintain the same scale color-values when I run the same code with other data.
There are 3 different variables to represent, one is the orientation:
plot.new()
ggplot(NS_Enero, aes(x = wd, y = ws, fill = manganese, size = manganese)) +
coord_polar() +
geom_point(shape = 21, show.legend = TRUE) +
scale_size(range = c(3,12),
labels = c("50", "150", "450", "1350", "4050"),
breaks = c(50, 150, 450, 1350, 4050),
name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) +
scale_fill_gradientn(colours = c("darkblue","blue", "yellow", "orange", "red"),
space = "Lab",
guide = "legend",
values = rescale(c(0, 150, 450, 1350, 4401),
from = c(0, 4401)),
labels = c("50", "150", "450", "1350", "4050"),
breaks = c(50, 150, 450, 1350, 4050),
name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) +
scale_x_continuous(limits= c(0,360),
breaks= c(0, 90, 180, 270),
labels = c("N","E","S","W"),
name = "") +
scale_y_continuous(name = "Distance (m)",
position = "left") +
theme_linedraw() +
theme(axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 8)) +
ggtitle(" NS_Enero")
When I try to run the same code with different data the output plot change the values of the scale, I have tried a lot of tips that I found in other questions, but I can't solve the problem with the scale representation. I think that the problem is in the values
from scale_fill_gradientn
...
Output 1:
Output 2 (different data):
The final result is ok but I want that the values of the scale range (size and color) to be constant in all the plots that I run with different range of data. The same values of size and color for values between 0 to 4050.
Thank you very much for your help.
Finally, adding limits
it worked.
This is the final code:
#Tamaño y color
plot.new()
ggplot(NS_Junio, aes(x = wd, y = ws, fill = manganese, size = manganese)) +
coord_polar() +
geom_point(shape = 21, show.legend = TRUE) +
scale_size(range = c(3,12),
labels = c("50", "150", "450", "1350", "4050"),
breaks = c(50, 150, 450, 1350, 4050),
limits = c(1,4050),
name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) +
scale_fill_gradientn(colours = c("darkblue","blue", "yellow", "orange", "red"),
space = "Lab",
guide = "legend",
values = rescale(c(0, 150, 450, 1350, 4401),
from = c(0, 4401)),
labels = c("50", "150", "450", "1350", "4050"),
breaks = c(50, 150, 450, 1350, 4050),
limits = c(1,4050),
name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) +
scale_x_continuous(limits= c(0,360),
breaks= c(0, 90, 180, 270),
labels = c("N","E","S","W"),
name = "") +
scale_y_continuous(name = "Distance (m)",
position = "left") +
theme_linedraw() +
theme(axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 8)) +
ggtitle(" NS_Enero")
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.