-1

我需要创建一个带有中间 x 轴和上下两个正 y 轴的条形图。它应该看起来像SAS 中的蝴蝶图,但 x 和 y 轴已转置。我的数据是雄性和雌性鱼的长度。

样本数据:

length <- c(12,13,15,14,13,16,18) 
sex<-c("m","m","m","f","f","f","f") 
dat=data.frame(length,sex)
4

1 回答 1

5

另一个术语是“相对水平条形图”。(打包的作者有多个:plotrix,但 Jim Lemon 是最有生产力的,他既是包的维护者,也是 .)的作者pyramid.plot。)这是一个示例的修改版本?pyramid.plot

install.packages("plotrix")
xy.pop<-c(3.2,3.5,3.6,3.6,3.5,3.5,3.9,3.7,3.9,3.5,3.2,2.8,2.2,1.8,
  1.5,1.3,0.7,0.4)
 xx.pop<-c(3.2,3.4,3.5,3.5,3.5,3.7,4,3.8,3.9,3.6,3.2,2.5,2,1.7,1.5,
  1.3,1,0.8)
 agelabels<-c("0-4","5-9","10-14","15-19","20-24","25-29","30-34",
  "35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74",
  "75-79","80-44","85+")
 mcol<-plotrix::color.gradient(c(0,0,0.5,1),c(0,0,0.5,1),c(1,1,0.5,1),18)
 fcol<-plotrix::color.gradient(c(1,1,0.5,1),c(0.5,0.5,0.5,1),c(0.5,0.5,0.5,1),18)
 # removed labels in center but you could run the example and see another approach
 par(mar=plotrix::pyramid.plot(xy.pop,xx.pop, labels=rep("",18),
  main="Australian population pyramid 2002",lxcol=mcol,rxcol=fcol,
  gap=0,show.values=TRUE))

在此处输入图像描述

于 2013-05-11T19:26:41.730 回答