R 是否可以删除堆叠的钢筋边界线?
我已经创建了下面的堆叠条形图。我想删除酒吧两种颜色之间的白色边界线。这可能吗R 是否可以删除堆叠的钢筋边界线?,r,R,我已经创建了下面的堆叠条形图。我想删除酒吧两种颜色之间的白色边界线。这可能吗 counts<- structure(list( A = c(51,11), B = c(51,11), C = c(31,9), D = c(46,3), E = c(20,3), F = c(57,29), G = c(31,6), H = c(6,0)), .Names = c("I'm sure of myself when I do science activities"
counts<- structure(list(
A = c(51,11),
B = c(51,11),
C = c(31,9),
D = c(46,3),
E = c(20,3),
F = c(57,29),
G = c(31,6),
H = c(6,0)),
.Names = c("I'm sure of myself when I do science activities",
"I would consider a career in science",
"I expect to use science when I get out of school",
"Knowing science will help me earn a living",
"I will need science for my future work",
"I know I can do well in science",
"Science will be important to me in my life’s work",
"I cannot do a good job with science"
),
class = "data.frame",
row.names = c(NA, -2L)) #4L=number of numbers in each letter vector#
attach(counts)
print(counts)
# barplot
colors <- c("slategray3","dodgerblue4")
counts <- counts[, order(colSums(counts))]
xFun <- function(x) x/2 + c(0, cumsum(x)[-length(x)])
par(mar=c(2, 22, 4, 2) + 0.1) # this sets margins to allow long labels
byc <- barplot(as.matrix(counts), horiz=TRUE, col=colors, #main="N=35"#,
border=FALSE, las=1, xaxt='n',
ylim = range(0, 12), xlim = range(-10, 100),
width = 1.35)
# labels
labs <- data.frame(x=as.vector(sapply(counts, xFun)), # apply `xFun` here
y=rep(byc, each=nrow(counts)), # use `byc` here
labels=as.vector(apply(counts, 1:2, paste0, "%")),
stringsAsFactors=FALSE)
labs$labels[labs$labels %in% paste0(0:(8*100)/100, "%")] <- "" #masks labels <8
invisible(sapply(seq(nrow(labs)), function(x) # `invisible` prevents unneeded console
output
text(x=labs[x, 1:2], labels=labs[x, 3], cex=.9, font=2, col=0)))
#adds % to scale
scale <- seq(0, 100, by = 20)
axis(side = 1, at = scale, labels = paste0(scale, "%"), cex.axis = 1)
#this adds gridlines
grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted",
lwd = par("lwd"), equilogs = TRUE)
# legend (set `xpd=TRUE` to plot beyond margins!)
legend(15,14.5, legend=c("Agree","Strongly Agree"),
fill=colors, horiz = T, bty='n', xpd=T)
counts您可以尝试:border=NA,
byc <- barplot(as.matrix(counts), horiz=TRUE, col=colors, #main="N=35"#,
border=NA, las=1, xaxt='n',
ylim = range(0, 12), xlim = range(-10, 100),
width = 1.35)
byc谢谢!我如何删除图例框周围的边框?相同:legend(15,14.5,legend=c(“同意”,“强烈同意”),fill=colors,horiz=T,bty='n',xpd=T,border=NA)
。函数的帮助页面对于此类问题非常有用。