本文介绍了对齐x轴以绘制与网格的一致使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试使用这里。我使用这个数据库的CSV版本来显示每年发现的外植体的数量。一个简单的脚本是 bulkdata< - read.csv('file.csv',head = 1,sep = ,') pdf(file =yearcount.pdf,family =Times) bins< - seq(min(bulkdata $ discovered,na.rm = T),max(bulkdata $发现,na.rm = T),by = 1) hist(bulkdata $ discovered,breaks = bins,col ='gray',ylab =Discovered,xlab =Year,main = (2,at = seq(0,100,by = 10)),b = b(b,b) ) grid(nx = 10) hist(bulkdata $ found,breaks = bins,col ='gray',ylab =Discovered,xlab =Year,main = TRUE) dev.off() 问题是 xaxis 不与 y轴的 0 c>。这是一个问题,因为 grid() 绘制的线不代表任何,因为它们不与刻度对齐!我尝试添加 axis(1,at = seq(1989,2012,by = 1))选项 line = -1 来修正,但是这种方式正确地绘制了 轴,但网格开始 轴下方。 解决方案 ?grid 说: 这里有一个建议: par(las = 1,bty =l)h col ='gray',ylab =Discovered,xlab =Year ,main =, ylim = c(0,100),axes = FALSE) yrs< - 1989:2012 yvals< - seq(0,100,by = 10) axis(1,at = yrs) axis(2,at = yvals) abline(h = yvals,v = yrs,col =grey,lty = 3) hist(bulkdata $ discovered,breaks = bins, col ='gray',ylab =Discovered,xlab =Year,main =,add = TRUE) > I'm trying to build an histogram using data available from here. I'm using using the CSV version of this database to display the number of exoplantes discovered per year. A simple script would bebulkdata <- read.csv('file.csv',head=1,sep=',')pdf(file="yearcount.pdf",family="Times")bins <- seq(min(bulkdata$discovered,na.rm=T),max(bulkdata$discovered,na.rm=T),by=1)hist(bulkdata$discovered,breaks=bins,col='gray',ylab="Discovered",xlab="Year",main="",ylim=c(0,100),axes=FALSE)axis(1, at=seq(1989,2012,by=1))axis(2, at=seq(0,100,by=10))grid(nx=10)hist(bulkdata$discovered,breaks=bins,col='gray',ylab="Discovered",xlab="Year",main="", add=TRUE)dev.off()The problem is that the xaxis is not aligned with the 0 point of the yaxis. This is a problem because the lines drawn by grid() does not mean anything because they are not aligned with the ticks! I tried to add in axis(1, at=seq(1989,2012,by=1)) the option line=-1 to correct but this way the axis is correctly drawn but the grid start below the axis. Maybe a non standard package is needed? 解决方案 ?grid says:So here's a suggestion:par(las=1,bty="l")h <- hist(bulkdata$discovered,breaks=bins, col='gray',ylab="Discovered",xlab="Year",main="", ylim=c(0,100),axes=FALSE)yrs <- 1989:2012yvals <- seq(0,100,by=10)axis(1, at=yrs)axis(2, at=yvals)abline(h=yvals,v=yrs,col="gray",lty=3)hist(bulkdata$discovered,breaks=bins, col='gray',ylab="Discovered",xlab="Year",main="", add=TRUE)I would consider making the grid lines a little bit sparser (e.g. every 5 years?) 这篇关于对齐x轴以绘制与网格的一致使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 04:00