Ggplot2 geom_bar plot where..count .. greater than X

How do you say ggplot to construct points only if the number is greater than the X . I know this should be easy, but I couldn't figure it out. something like

ggplot(items,aes(x=itemname,y=..count..))+geom_bar(y>X)

      

0


source to share


2 answers


If I understood your question correctly (you didn't provide the example data), the simplest way is to create the dataframe you want to plot outside of ggplot. So

##Example data
items = data.frame(itemname = sample(LETTERS[1:5], 30, replace=TRUE))
##Use table to count elements
items_sum = as.data.frame(table(items))

      



Then sketch

X = 4
ggplot(items_sum[items_sum$Freq > X,], aes(x=items,y=Freq)) + 
    geom_bar(stat="identity")

      

+1


source


I may be wrong here, but can you just pass the subset code through geom_bar ()?



ggplot(items_sum, aes(x=items,y=Freq)) + geom_bar(stat="identity", subset=.(Freq>4))

      

0


source







All Articles