我一直在为一个类编写一些代码,并且在如何从箱线图中删除x和y标签方面遇到了麻烦。我打算将其放置在第一张图中,因此它们是多余的。
如果有人也知道如何在我的线图中添加0线,那也将是惊人的!
代码:
#load data up
library(readxl)
TempData <- read_excel("R Data/TempData.xlsx")
View(TempData)
#initiliase relevant packages #ggplot2 for creating data visulation and viridis to allow for colour gradients
library(ggplot2)
library(viridis)
#plot line graph
g1 <- ggplot(TempData, aes(x = Year, y = GAT, color = GAT)) +
geom_line(size = 1.5) +
geom_smooth(method=loess, se=TRUE, col = "black") +
scale_colour_gradient2(low = "green", mid = "yellow" , high = "red", midpoint=median(TempData$GAT)) +
labs(title = "Global Average Temperature", subtitle = "From 1850 to 2018") +
xlab("Year") + ylab ("Average Temperature") +
theme(plot.title = element_text(face = "bold", hjust = 0.5, size = 16)) +
theme(plot.subtitle = element_text(face = "italic", hjust = 0.5, size = 10, colour = "Orange")) +
theme_light()
plot(g1)
#plot boxplot
g2 <- ggplot(TempData, aes(x="Year", y=TempData$GAT)) + geom_boxplot(outlier.colour = "red", outlier.fill = "red",outlier.shape = 21, outlier.size = 1)
labs(x=" ", y=" ") +
stat_summary(fun.y = mean, geom = "point", size = 2.5, colour = "orange") +
theme_light()
plot(g2)
#arrange two graphs to boxplot sits in top corner of line graph
g1 + annotation_custom(ggplotGrob(g2), xmin = 1840, xmax = 1930, ymin = 0.20, ymax = 0.88)
答案 0 :(得分:0)
您可以通过以下方式使用theme
:
... + theme(axis.title.x=element_blank(), axis.title.y=element_blank())
这将删除情节的x,y标签