'How to exclude zero from plot?
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
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.
Solution 1:[1]
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()
Solution 2:[2]
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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TarJae |
| Solution 2 | Rfanatic |



