[英]How to break axis in a barplot (maybe using plotrix gap.barplot)?
[英]How to replace axis in gap.barplot in R
我一直在嘗試找出如何在R中的gap.barplot中替換x軸。首先,標簽存在問題:
附上我的代碼:
Samples Conc stdlo stdhi
SampA 5000 0 0
SampB 100 0 11
SampC 80 0 20
rm(list=ls())
library(plotrix)
C.dat <- read.csv("G:/...../C.csv", head = TRUE)
C.lab = C.dat$Samples
C.conc = C.dat$Conc
C.lostd = C.dat$stdlo
C.histd = C.dat$stdhi
par(mar=c(6,6,5,2))
barplot = gap.barplot(C.conc, gap = c(200,1000), xlab = "Samples",
ylab ="C Conentration (pg/mL)", main = "C in X and Y", las = 2,
xlim = c(0,4), ytics = c(0,1000,1500,5100), cex.lab = 1.5)
mtext("SampA", side = 1, at= 1.0, cex=1.0)
mtext("SampB", side = 1, at= 2.0, cex=1.0)
mtext("SampC", side = 1, at= 3.0, cex=1.0)
arrows(barplot,C.conc-0 ,barplot,C.conc+C.histd,code=2,angle=90,length=.1)
我最大的問題是,當我在gap.barplot參數中停留在軸= FALSE時,它會發出警告,並且不會生成任何圖。 我想擺脫“ 1 2 3”軸標簽和刻度線。
另外,如果有人知道如何將y軸標簽向左移動更多,那就太好了。
有什么建議么?
您可以嘗試一下。 我稱您的數據框為df
。
我在gap.barplot
調用中添加了xaxt = "n"
。
From ?par
: xaxt: A character which specifies the x axis type. Specifying "n" suppresses plotting of the axis.
xaxt: A character which specifies the x axis type. Specifying "n" suppresses plotting of the axis.
然后axis
被用來添加與x軸labels
的位置at
,但是沒有蜱( tick = FALSE
)。 y軸的標簽添加了多行mtext
library(plotrix)
par(mar=c(6,6,5,2))
gap.barplot(df$Conc, gap = c(200,1000),
xlab = "Samples", ylab ="", main = "C in X and Y", las = 2,
xlim = c(0, 4), ytics = c(0, 1000, 1500, 5100), cex.lab = 1.5,
xaxt = "n")
axis(side = 1, at = seq_along(df$Sample), labels = df$Sample, tick = FALSE)
mtext("C Concentration (pg/mL)", side = 2, line = 4)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.