user12257
user12257

Reputation: 11

Issues when modifying axis color label in ggplot2

I have a basic question which has turned a headache for me. I want to change the color for the axis value in a plot to blue, but it has been impossible. In the code, I´m using, I plot the mean and Confidence intervals (CI) values for a data summary. I some tutorials to change this (http://docs.ggplot2.org/0.9.2.1/theme.html & How to change axis-label color in ggplot2?). Nevertheless, when I apply the function to change the labels to blue, the axis names and also the CI dissapear. I wanted to know what am I doing wrong.

Please find attached the code and the data set!

Thanks for any help you can provide!

DATA

                     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")

CODE

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. 

Upvotes: 1

Views: 217

Answers (1)

jazzurro
jazzurro

Reputation: 23574

This may be what you are after. It seems that your geom_errorbar() part was not working. If you check ?geom_errorbar, you do not see y; y is not necessary. One more thing. You could create the by mean object with the following qplot() part.

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)

enter image description here

Upvotes: 1

Related Questions