如何更改ggplot2中的轴标签颜色? [英] How to change axis-label color in ggplot2?

查看:1667
本文介绍了如何更改ggplot2中的轴标签颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试过

  ... + xlab(New label,color =darkgrey)

  ... + xlab(New label,color =darkgrey)

这个说法没有用。我看看?xlab ,但它不包含任何颜色参数。有没有可能改变它?如何使用 opts

试试这个,

  dat < -  data.frame(x = 1:5,y = 1:5)
p < - ggplot(dat ,aes(x,y))+ geom_point()
p + opts(axis.title.x = theme_text(color =red),
axis.title.y = theme_text(color =blue ))

这个页面是了解所有选项的好起点。



ggplot2 0.9.2 opts 已被弃用。当前版本的语法更像这样:

  p + theme(axis.title.x = element_text(color =red),
axis.title.y = element_text(color =blue))



'p>有详述转换指南以更新您的代码。


I have tried

... + xlab("New label", colour="darkgrey")

and

... + xlab("New label", color="darkgrey")

But it says this argument is unused. I look into ?xlab, but it doesn't include any color parameter. Is it possible to change it? How?

解决方案

Try this, using opts:

dat <- data.frame(x = 1:5,y = 1:5)
p <- ggplot(dat,aes(x,y)) + geom_point()
p + opts(axis.title.x = theme_text(colour = "red"),
         axis.title.y = theme_text(colour = "blue"))

This page is a good starting point for learning about all the options.

Since the release of ggplot2 0.9.2 opts has been deprecated. The syntax for the current release would be something more like this:

p + theme(axis.title.x = element_text(colour = "red"),
          axis.title.y = element_text(colour = "blue"))

There is detailed transition guide for updating your code.

这篇关于如何更改ggplot2中的轴标签颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆