-1

I want to use R to produce a graph that looks like this:

https://dl.dropboxusercontent.com/u/9297902/R_desired_output.png

The scale runs from 0 on the left to 100 on the right, with each major category (poor, fair, etc.) taking up 25%. I think I need to: 1. make multiple background boxes for colors (#D55E00, #E69F00, #56B4E9, #009E73) 2. change gridline color, positions (from at my y category values to between them), and thickness 3. select an appropriate symbol (that allows me to have outline & fill with bar?) 4. place for labels on top of graph (Poor, Fair, Good, Excellent) in a more controlled, predictable manner

Here is where I am so far:

# assemble data
metric<-c("Bottom Substrate","Deposition",
   "Substrate Stability","In-stream Cover",
   "Pool Substrate","Pool Quality",
   "Pool Variability","Channel Alteration",
   "Channel Sinuosity","Width/Depth",
   "Hydrolic Diversity","Canopy Cover",
   "Bank Vegetation","Immediate Land Use",
   "Flow Related Refugia")
score<-c(10.53,18.18,13.33,9.09,
   26.32,6.67,6.67,57.14,
   18.18,40.00,27.27,
   9.09,73.33,71.43,27.27)

hab<-data.frame(metric,score) #create data frame

library(ggplot2)

# colorblind friendly colors
# #000000 # Black
# #E69F00 # Orange
# #56B4E9 # Sky Blue
# #009E73 # bluish Green
# #F0E442 # Yellow
# #0072B2 # Blue
# #D55E00 # Vermillion
# #CC79A7 # reddish Purple

# set up to remove x axis values, and axis titles
theme_mod <- theme(axis.text.x = element_blank(),
   axis.title.x = element_blank(), 
   axis.title.y = element_blank()) 

qplot(score,metric) +
   geom_point(aes(score,metric), size=6, pch="|") + # pch gets the symbol I want, how to lose the dot?
   scale_x_continuous(limits=c(0,100)) + # locks scale to be 0-100, whcih I want
   opts(title="Poor                    Fair                       Good                        Excellent") +
   theme_mod # removes axis stuff

So, I'm kind of far from ready to go. It seems to have reordered my dataset for some reason, too.

I've looked here for possibilities, but I'm not sure which way to go:

Using ggplot2 in R, how do I make the background of a graph different colours in different regions?

Sorry I'm a bit of a novice - thanks in advance for any pointers.

Community
  • 1
  • 1
Steve T
  • 73
  • 1
  • 11

1 Answers1

2

You can use geom_rect together with geom_line too simulate this effect. If you really want lines instead of points you could add shape="|" in geom_point.

   p<-ggplot(hab,aes(x=score, y=metric))+theme_classic()+geom_rect(aes(xmin = 0 , xmax = 25) , ymin = -Inf , ymax = Inf ,fill = "#F15922") + 
geom_rect(aes(xmin = 25 , xmax = 50) , ymin = -Inf , ymax = Inf ,fill = "#F7941E")+
geom_rect(aes(xmin = 50 , xmax = 75) , ymin = -Inf , ymax = Inf ,fill = "#00BAF2")+
geom_rect(aes(xmin = 75 , xmax = 100) , ymin = -Inf , ymax = Inf ,fill = "#00A975")+
geom_vline(xintercept=seq(0,100,by=25),colour="white",size=1.5)+
geom_hline(yintercept=c(seq(0,0.5,by=0.1),seq(1.5,15.5,by=1),seq(15.5,16,by=0.1)),colour="white",size=1.5)+
geom_point(colour="white", size=4) + geom_point(colour = "black",size=3)+
geom_text(aes(label = "Poor", x = 12.5, y = 16), vjust = 1.2,size=4)+
geom_text(aes(label = "Fair", x = 37.5, y = 16), vjust = 1.2,size=4)+
geom_text(aes(label = "Good", x = 62.5, y = 16), vjust = 1.2,size=4)+
geom_text(aes(label = "Excellent", x = 87.5, y = 16), vjust = 1.2,size=4)

p

enter image description here

Jonas Tundo
  • 6,137
  • 2
  • 35
  • 45
  • Almost exactly what I needed. I just need to get rid of "score" "metric" & the 0,25,50,75,100 along bottom, and the black lines of frame on bottom and left. Thanks so much for your excellent help - I've learned some tricks! – Steve T Jun 14 '13 at 10:54