-1

我想使用 R 生成如下图:

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

量表从左边的 0 到右边的 100,每个主要类别(差、一般等)占 25%。我想我需要: 1. 为颜色制作多个背景框(#D55E00、#E69F00、#56B4E9、#009E73) 2. 更改网格线颜色、位置(从我的 y 类别值到它们之间)和厚度 3。选择一个合适的符号(允许我有轮廓并用条形填充?) 4. 以更可控、可预测的方式将标签放置在图表顶部(差、一般、好、优秀)

这是我到目前为止的位置:

# 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

所以,我还没有准备好去。由于某种原因,它似乎也重新排序了我的数据集。

我在这里寻找可能性,但我不确定该走哪条路:

在 R 中使用 ggplot2,如何在不同区域使图形的背景颜色不同?

抱歉,我有点新手 - 在此先感谢您的任何指点。

4

1 回答 1

2

你可以和toogeom_rect一起使用geom_line来模拟这个效果。如果你真的想要线条而不是点,你可以添加shape="|".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

在此处输入图像描述

于 2013-06-13T20:59:45.673 回答