【问题标题】:Size of labels for x-axis and y-axis ggplot in RR中x轴和y轴ggplot的标签大小
【发布时间】:2013-01-17 01:33:34
【问题描述】:

我有一个 ggplot 代码,我想更改 x 轴和 y 轴的标签大小。

代码:

df.m <- melt(df, names(df)[2:3], names(df)[1])
df.m$Results <- factor(df.m$Results)
df.m$HMn25_30.h <- strptime(as.character(df.m$HMn25_30.h), format = "%Y-%m-%d %H:%M:%S")
p <- ggplot(df.m, aes(x = HMn25_30.h, y = value, group = variable, color = variable))
p <- p + scale_shape_manual(values=c(20,22))
p <- p + geom_point(aes(shape = Results), cex=4, color= "blue3")
p <- p + geom_line(size=.8)
p <- p + theme(axis.text.x = element_text(angle = 90, hjust = 1, size=13,color="darkred"))
p <- p + scale_color_manual(values=c("Red"))
p <- p + ylim(-1,8)
p <- p + xlab('Date and Time') 
p <- p + ylab('Temperature') 
p <- p + ggtitle("Temporal Outliers of Node 25 ") + theme(plot.title = element_text(lineheight=3, face="bold", color="black", size=29))
p

换句话说,应该更改“温度”和“日期和时间”的字体和大小。

【问题讨论】:

  • 您已经在使用函数theme,但您似乎没有阅读它的文档。我建议你现在就这样做。我怀疑你会发现它很有启发性。

标签: r size ggplot2


【解决方案1】:

您可以应用theme 的不同选项:

p <- ggplot(df.m, aes(x = HMn25_30.h, y = value, group = variable, color = variable))
    p <- p + scale_shape_manual(values=c(20,22))
    p <- p + geom_point(aes(shape = Results), cex=4, color= "blue3")
    p <- p + geom_line(size=.8)
    p <- p + theme(axis.text.x = element_text(angle = 90, hjust = 1, size=13,color="darkred"))
    p <- p + scale_color_manual(values=c("Red"))
    p <- p + ylim(-1,8)
    p <- p + theme_bw()
    p <- p + xlab('Date and Time') 
    p <- p + ylab('Temprature') 
    p <- p + ggtitle("Temporal Outliers of Node 25 ") + theme(plot.title = element_text(lineheight=3, face="bold", color="black", size=29))
    p <- p + labs(x = "Date-Time ", y = "Temprature  ")
    p <- p + theme(axis.title.y = element_text(size = rel(1.8), angle = 90))
    p <- p + theme(axis.title.x = element_text(size = rel(1.8), angle = 00))
    p

【讨论】:

  • 这些也可以应用在单个 theme() 调用中,如下所示:theme(scale_shape_manual(values=c(20,22)), geom_point(aes(shape = Results), cex=4, color= "blue3"), etc
  • 单个theme() 调用可修改图中的所有文本元素:theme(text = element_text(size = 15))
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 2017-07-26
  • 2016-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多