Skip to content
Prev 385128 / 398503 Next

hist from a list

Hello,

Thanks for the data in dput format.
If you run

str(bwchist)

you will see that what you have is a data.frame, yes, but, with columns 
of class "list", not vectors.
So the first step is to make them vectors, to unlist the lists. I will 
do it applying function unlist() to each of the columns. Since lapply 
returns a list, I remake a data.frame. The original is kept unchanged, 
the new object is bwch.

bwch <- lapply(bwchist, unlist, recursive = FALSE)
bwch <- do.call(cbind.data.frame, bwch)
str(bwch)


Now that everything is as it should, here are two ways of plotting bar 
graphs.

#--- base R
x11(width = 11.5, height = 6)
old_par <- par(mar =? par("mar") + c(1, 0, 0, 0))
bp <- barplot(bwch$reval, yaxt = "n", ylim = c(-1, 0.4))
axis(1, at = bp, labels = bwch$Accion, las = 2)
axis(2, at = pretty(bwch$reval))
par(old_par)


#--- package ggplot2
library(ggplot2)

x11(width = 11.5, height = 6)
ggplot(bwch, aes(factor(Accion, levels = Accion), reval)) +
 ? geom_col() +
 ? theme(axis.text.x = element_text(angle = 60, hjust = 1))


Hope this helps,

Rui Barradas

?s 19:48 de 03/08/2020, Pedro p?ramo escreveu: