r - 如何在 R 中删除重复的 x 轴标签
问题描述
我试图获得按性别和大小间隔( )分组的barplot
代表平均着色百分比( )。但是,x 轴上的标签出现重复。我想为每个级别获取一个标签(第一列和第二列一起使用“50-55”,第三列和第四列一起使用“55-60”,依此类推)。我怎么能这样做?valores
class
class
这是我的代码:
par(mar=c(7,4,4,2)+0.1)
class<-factor(coloration$clase.2,levels=c("50-55","55-60","60-65","65-70","70-75","75-80"))
sex<-factor(coloration$sexo,levels=c("M","H"))
valores<-coloration$perc.greenblue
graf<-barplot(tapply(valores,list(sex,class),mean),beside=T,axes=F,ylim=c(0,50),col=c(grey.colors(2)),axisnames=F ,xlab=("Sex and size"),ylab=("% mean coloration"),las=1)
axis(2,at=c(0,5,10,15,20,25,30,35,40,45,50),labels=c(0,5,10,15,20,25,30,35,40,45,50),las=1)
labs<-as.character(class)
text(graf,par("usr")[3]-0.25,srt=0,adj = c(0,2),labels=labs,xpd=T,cex=1)
legend(locator(1),c("Adult males","Adult females"),fill=c(grey.colors(2)),bty="n")
编辑:这里有一些可重现的代码:
structure(list(edad = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "ADU", class = "factor"),
sexo = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("H", "M"), class = "factor"),
clase.2 = structure(c(2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L,
6L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L), .Label = c("50-55",
"55-60", "60-65", "65-70", "70-75", "75-80"), class = "factor"),
perc.greenblue = c(0.09, 0.32, 12.8, 94.32, 34.83, 0.04,
45.83, 12.34, 0.75, 34.82, 0.5, 0.05, 3.46, 0, 1.72, 0.07,
0.09, 0.2)), row.names = c(9L, 10L, 12L, 13L, 48L, 49L, 109L,
110L, 194L, 195L, 263L, 264L, 266L, 267L, 332L, 333L, 408L, 409L
), class = "data.frame")
解决方案
推荐阅读
- typo3-8.7.x - Typo3 8.7.x 云无法访问远程资源 http://repositories.typo3.org/mirrors.xml.gz
- python - Nginx (proxy_pass) + Gunicorn 无法访问
- makefile - GNU make:根据特定目录内容创建目标(1:1 目标目录映射)
- prometheus - 无法在 prometheus-adapter 中获取 springboot 执行器指标
- azure - 使用 REST API 创建 Azure App Insights 失败需要 ROLE
- ios - 如何发布私有 cocoapods 版本?
- javascript - 通过 Firebase 云消息从 android 应用程序向 Web 应用程序发送通知
- angular - NGRX - 重置状态时,选择器返回重置前的值
- c# - 如何使用 gson 在 android studio 中反序列化 c# http 响应
- c++ - 如何在二进制文件上附加数据?