在 ggplot2 中修改轴颜色标签时出现问题
Issues when modifying axis color label in ggplot2
我有一个让我头疼的基本问题。我想将绘图中轴值的颜色更改为蓝色,但这是不可能的。在我使用的代码中,我绘制了数据摘要的均值和置信区间 (CI) 值。我有一些教程可以改变这一点 (http://docs.ggplot2.org/0.9.2.1/theme.html & How to change axis-label color in ggplot2?)。然而,当我应用函数将标签更改为蓝色时,轴名称和 CI 消失了。我想知道我做错了什么。
代码和数据集见附件!
感谢您提供的任何帮助!
数据
PREY N Time sd se ci
1 Acromyrmex octospinosus 63 46.91254 36.535910 4.603092 9.201450
2 Camponotus sp. 66 12.05773 9.732161 1.197946 2.392464
pt <- structure(list(PREY = structure(1:2, .Label = c("Acromyrmex octospinosus",
"Camponotus sp."), class = "factor"), N = c(63, 66), Time = c(46.91254,
12.05773), sd = c(36.53591, 9.732161), se = c(4.603092, 1.197946
), ci = c(9.20145, 2.392464)), .Names = c("PREY", "N", "Time",
"sd", "se", "ci"), row.names = c(NA, -2L), class = "data.frame")
代码
bymean <- with(pt, reorder(PREY, -Time, mean))# REordenar por promedio
bymean
e <- qplot(bymean, pt$Time,size=3) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"))
e <- e + theme(legend.position = "none")
e + theme(axis.text.x = element_text(colour = "black"))
e
e + geom_errorbar(data = pt,
aes(x = pt$PREY, y = pt$Time,
ymin = pt$Time - pt$ci, ymax = pt$Time + pt$ci),
colour = "black", width = 0.4, size=0.5) +
xlab("Prey") +
ylab("Time (UNIDAD?)") +
ggtitle("iMMOBILISATION TIME")
e + theme(axis.text = element_text(colour = "blue"))
# After making this, the error bars and axis name dissapear.
这可能就是您想要的。您的 geom_errorbar()
部分似乎没有工作。如果勾选 ?geom_errorbar
,则看不到 y
; y
没有必要。还有一件事。您可以使用以下 qplot()
部分创建 by mean
对象。
qplot(PREY, Time, data = pt, stat = "summary", fun.y = "mean") +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
axis.text.x = element_text(colour = "black"),
axis.text = element_text(colour = "blue")) +
geom_errorbar(data = pt,
aes(x = PREY, ymin = Time - ci, ymax = Time + ci),
colour = "black", width = 0.4, size = 0.5)
我有一个让我头疼的基本问题。我想将绘图中轴值的颜色更改为蓝色,但这是不可能的。在我使用的代码中,我绘制了数据摘要的均值和置信区间 (CI) 值。我有一些教程可以改变这一点 (http://docs.ggplot2.org/0.9.2.1/theme.html & How to change axis-label color in ggplot2?)。然而,当我应用函数将标签更改为蓝色时,轴名称和 CI 消失了。我想知道我做错了什么。
代码和数据集见附件!
感谢您提供的任何帮助!
数据
PREY N Time sd se ci
1 Acromyrmex octospinosus 63 46.91254 36.535910 4.603092 9.201450
2 Camponotus sp. 66 12.05773 9.732161 1.197946 2.392464
pt <- structure(list(PREY = structure(1:2, .Label = c("Acromyrmex octospinosus",
"Camponotus sp."), class = "factor"), N = c(63, 66), Time = c(46.91254,
12.05773), sd = c(36.53591, 9.732161), se = c(4.603092, 1.197946
), ci = c(9.20145, 2.392464)), .Names = c("PREY", "N", "Time",
"sd", "se", "ci"), row.names = c(NA, -2L), class = "data.frame")
代码
bymean <- with(pt, reorder(PREY, -Time, mean))# REordenar por promedio
bymean
e <- qplot(bymean, pt$Time,size=3) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"))
e <- e + theme(legend.position = "none")
e + theme(axis.text.x = element_text(colour = "black"))
e
e + geom_errorbar(data = pt,
aes(x = pt$PREY, y = pt$Time,
ymin = pt$Time - pt$ci, ymax = pt$Time + pt$ci),
colour = "black", width = 0.4, size=0.5) +
xlab("Prey") +
ylab("Time (UNIDAD?)") +
ggtitle("iMMOBILISATION TIME")
e + theme(axis.text = element_text(colour = "blue"))
# After making this, the error bars and axis name dissapear.
这可能就是您想要的。您的 geom_errorbar()
部分似乎没有工作。如果勾选 ?geom_errorbar
,则看不到 y
; y
没有必要。还有一件事。您可以使用以下 qplot()
部分创建 by mean
对象。
qplot(PREY, Time, data = pt, stat = "summary", fun.y = "mean") +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
axis.text.x = element_text(colour = "black"),
axis.text = element_text(colour = "blue")) +
geom_errorbar(data = pt,
aes(x = PREY, ymin = Time - ci, ymax = Time + ci),
colour = "black", width = 0.4, size = 0.5)