Home > Mobile >  How to exclude zero from plot?
How to exclude zero from plot?

Time:03-17

I'm using a dynamic input variable button_var_fir for a dashboard via flexdashboard and shiny and hence, I can't subset the dataframe each time via e.g. df$variable > value or the like:

ggplot(df_scat, aes(!!input$button_var_fir, !!input$button_var_sec))   
    geom_boxplot(aes(fill= Gen_type), alpha = 0.5, alpha = 0.75)  

At the moment, the plot looks like

img

and as you can see, I would like to get rid of all those zeros. They are present because I replaced NAs with zeros but however, in plots like this, I don't have to keep those zero values and it would look much better and more reasonable without.

CodePudding user response:

You could subset your data with which:

df_scat[which(df_scat$your_column > 0),]

Here is an example:

ggplot(mtcars[which(mtcars$am>0),], aes(x=factor(am), y=mpg))  
  geom_point()

enter image description here

CodePudding user response:

Or by you could simply remove the zeroes with subset(dataset, variable!= 0) in your ggplot

Sample code:

ggplot(subset(mtcars,am != 0), aes(x=factor(am), y=mpg)) 
  geom_point()

Plot:enter image description here

  • Related