我有以下代码用ggplot2
创建极坐标图但是当我用其他数据运行相同的代码时,我无法保持相同的比例颜色值。
要表示3个不同的变量,一个是方向:
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")
当我尝试使用不同的数据运行相同的代码时,输出图改变了比例的值,我尝试了很多我在其他问题中找到的技巧,但是我无法解决问题。比例表示。我认为问题出在values
来自scale_fill_gradientn
...
输出1:
输出2(不同数据):
最终结果还可以,但我希望在我使用不同数据范围运行的所有图中,比例范围(大小和颜色)的值保持不变。 0到4050之间的值的大小和颜色值相同。
非常感谢你的帮助。
答案 0 :(得分:1)
最后,添加limits
它有效。
这是最终代码:
#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")