调整R注释中的y轴,使其可见(使用'plot'命令)

问题描述 投票:0回答:1

我正在尝试在R中导出图形,以便可以将其放在海报上,但是我的y轴标签不清晰可见。它们看起来像被挤压在图的轴和边缘之间。当我将图像导出为PNG文件时,效果不好。如何调整代码,使其显示这些标签?

如果在此示例中运行代码,您应该会看到问题。

此外,为什么我的R ^ 2值不按我指定的粗体显示??

任何帮助都会很棒,谢谢大家!

((注:这显然是虚假数据,由本例组成)。

data1 <- data.frame(height = c(1,2,3,4,5,6,7,8,9), camera = c(1,2,3,4,5,6,7,8,9))
data2 <- data.frame(height = c(1,2,3,4,5,6,7,8,9), camera = c(1,2,3,4,5,6,7,8,9))
data3 <- data.frame(height = c(1,2,3,4,5,6,7,8,9), camera = c(1,2,3,4,5,6,7,8,9))
data4 <- data.frame(height = c(1,2,3,4,5,6,7,8,9), camera = c(1,2,3,4,5,6,7,8,9))
data5 <- data.frame(height = c(1,2,3,4,5,6,7,8,9), camera = c(1,2,3,4,5,6,7,8,9))

###############PNG Settings#############
png("example.png", width=1000, height=700)

##############dataset1#####################
par(mfrow=c(2,3))

plot(data1$height, 
     data1$camera, main = "9 DAT",
     xlab = "GT Height (m)", ylab = "DTM Height (m)", las=1, pch=19,
     cex=2, cex.main=2, cex.lab=2, cex.axis=2)



abline(lm(data1$camera~data1$height), col='red', lwd = 3)

mod1<- lm(data1$camera~data1$height)
summary(mod1)

text(4, 8, label = "y = x", font=2, cex = 2)
text(4, 7, font=2, label = expression("R"^"2"* "= 1"), cex=2)


###########dataset2#################

plot(data2$height, data2$camera, main = "15 DAT", xlab = "GT Height (m)",
     ylab = "DTM Height (m)", las = 1, pch = 19,  cex=2, cex.main=2, cex.lab=2, cex.axis=2)

mod2 <- lm(data2$camera ~ data2$height)
summary(mod2)
abline(mod2, col='red', lwd=3)

text(x=4, y=8, labels = "y = x", font=2, cex=2)
text(x=4, y=7, font=2, labels = expression('R'^'2'* '= 1'), cex=2)

#################dataset3##############################


plot(data3$height, data3$camera, main = "21 DAT", xlab = "GT Height (m)",
     ylab = "DTM Height (m)", las = 1, pch = 19,  cex=2, cex.main=2, cex.lab=2, cex.axis=2)

mod3 <- lm(data3$camera ~ data3$height)

summary(mod3)
abline(mod3, col='red', lwd=3)

text(x=4, y=8, labels = "y = x", font=2, cex=2)
text(x=4, y=7, font=2,labels = expression('R'^'2'* '= 1'), cex=2)

############dataset4##################


plot(data4$height, data4$camera, main = "27 DAT", xlab = "GT Height (m)",
     ylab = "DTM Height (m)", las = 1, pch = 19,  cex=2, cex.main=2, cex.lab=2, cex.axis=2)

mod <- lm(data4$camera ~ data4$height)

summary(mod)

abline(mod, col='red', lwd=3)

text(x=4, y=8, labels = "y = x", font = 2, cex=2)
text(x=4, y=7, labels = expression('R'^'2'* '=1'), font = 2, cex=2)

####################dataset5#######################

plot(data5$height, data5$camera, main = "35 DAT", xlab = "GT Height (m)",
     ylab = "DTM Height (m)", las = 1, pch = 19,  cex=2, cex.main=2, cex.lab=2, cex.axis=2)

mod <- lm(data5$camera ~ data5$height)

summary(mod)
abline(mod, col='red', lwd=3)

text(x=4, y=8, labels = "y = x", font = 2, cex=2)
text(x=4, y=7, labels = expression('R'^'2'* '=1'), font = 2, cex=2)

############End of Image###############
dev.off()
r plot export axis-labels
1个回答
0
投票

我假设您想使绘图大小和边距大小保持相同。

ylab中的plot设置为空白:

plot(data1$height, 
     data1$camera, main = "9 DAT",
     xlab = "GT Height (m)", ylab = '', las=1, pch=19,
     cex=2, cex.main=2, cex.lab=2, cex.axis=2)

然后使用mgp参数手动指定。默认值为c(3,1,0)

title(ylab = "DTM Height (m)", mgp=c(2.3,1,0), cex.lab=2)
© www.soinside.com 2019 - 2024. All rights reserved.