I have list of data.frame that needed to be categorized into different set. I found some post about how to manipulate data.frame list. However, I tried given soluion in SO and couldn't generate stack bar plot by using ggplot2
. I've read about ggplot2
package's vignette, learned how to use basic features. The points, when I tried to split each data.frame in the list by its pos.score
column, result gonna be nested list. working with nested list in R is not desired. Is there any easier and efficient way to categorize data.frame in the list more elegantly ? How to create stack bar plot for file bar (I mean, for each data.frame object that I specified) after splitting data.frame ? How can I make plot data available for ggplot
function ? Is there any efficient way to do this ? This is my first post, so if made mistake on my question, please remind me. Thanks a lot.
simulation data :
dfList <- list(
hotan = data.frame( begin=seq(1, by=6, len=25), end=seq(4, by=6, len=25), pos.score=sample(30, 25)),
aksu = data.frame( begin=seq(3, by=9, len=30), end=seq(6, by=9, len=30), pos.score=sample(45, 30)),
korla = data.frame( begin=seq(6, by=8, len=45), end=seq(11, by=8, len=45), pos.score=sample(52, 45))
)
categorize data.frame
catg <- lapply(myList, function(elm) {
res <- split(elm, ifelse(elm$pos.score >=16, "valid", "invalid"))
})
doing this way, I got nested list, can't be desired for generating bar plot. I am seeking more elegant solution like using tidyr
package. I am quite new with using these packages. How can I make it happen ? Any idea please?
This is nasty way to get rid of nested list, Is there any beautiful solution on that ?
unlist(lapply(catg, unlist))
Edit
I intend to get list of data.frame like this :
$hotan.valid
$hotan.invalid
$aksu.valid
$aksu.invalid
$korla.valid
$korla.invalid
then generate stack bar plot for file bar (each data.frame). How can I make this happen easily ? This is mockups of desired bar plot:
I am stuck how to generate stack bar plot after I remove nested list. How can I achieve my desired stack bar plot for file bar ? How can I make it easier for categorizing each data.frame in the list ?