[英]Changing the color bar font in R plots
我在 R 中执行光栅的 plot,我需要图表上的所有文本和数字具有相同的字体和字体大小。 字体应该是 Times New Roman(衬线系列),它的大小应该是 12。我使用的代码是:
GHI <- rasterFromXYZ(Solar_Potential)
cuts <- c(1300,1325,1350,1375,1400,1425,1450,1475,1500,1525,1550,1575,1600)
pal <- colorRampPalette(c("yellow","red"))
plot(GHI,breaks = cuts,col = pal(13),
xlab = "Longitude",ylab = "Latitude",family = "serif")
title("Global horizontal irradiation",family = "serif")
但是,右侧的颜色条保持默认字体,并且与图表的 rest 相比,标题为粗体并且具有更大的字母。 谁能帮我解决这个问题?
使用raster
的默认plot
function 可能很难实现这一点,这似乎不允许更改图例的字体系列。
您可以使用ggplot2
来实现这一点,使用类似这样的东西(因为您不提供GHI
,您可能需要进行调整):
library(ggplot2)
ggplot() +
geom_tile(data=as.data.frame(rasterToPoints(GHI)), aes(x=x, y=y, fill=layer)) +
scale_fill_gradientn(colours=pal(13), breaks=seq(1300, 1600, length.out=13)) +
theme_classic(base_size=12, base_family="serif") +
theme(panel.border=element_rect(fill=NA, size=1),
plot.title=element_text(hjust=0.5, size=12),
axis.text=element_text(size=12)) +
labs(x="Longitude", y="Latitude", title="Global horizontal irradiation")
编辑:
我错了; 我相信字体系列可以全局传递,但字体大小取决于图形设备,因此使用ggplot2
可能仍然更容易获得目标字体大小。
要获得与 plot 相同的尺寸,您可以尝试:
par(family="serif")
plot(GHI, breaks = cuts, col = pal(13),
xlab = "Longitude", ylab = "Latitude", cex.lab=1)
title("Global horizontal irradiation", font.main = 1, cex.main=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.