He creado el gráfico de barras apiladas a continuación. Me gustaría eliminar la línea del borde blanco entre los dos colores de la barra. es posible?

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) 

enter image description here

r
0
freeazabird 20 ene. 2021 a las 17:27

1 respuesta

La mejor respuesta

Puedes probar: 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)
1
pascal 20 ene. 2021 a las 14:31