I have the dataframe below:
etf_id<-c("a","b","c","d","e","a","b","c","d","e","a","b","c","d","e")
factor<-c("A","A","A","A","A","B","B","B","B","B","C","C","C","C","C")
normalized<-c(-0.048436801,2.850578601,2.551666490,0.928625186,-0.638111793,
-0.540615895,-0.501691539,-1.099239823,-0.040736139,-0.192048665,
0.198915407,-0.092525810,0.214317734,2.550478998,0.024613778)
df<-data.frame(etf_id,factor,normalized)
and Im trying to remove outliers with 2 ways. First I try with outlier.color = NA,outlier.size = 0,outlier.shape = NA
:
library(ggplot2)
library(plotly)
ggplotly(df %>%
ggplot(aes(factor, normalized, color = factor)) +
geom_boxplot(outlier.color = NA,outlier.size = 0,outlier.shape = NA) +
coord_cartesian(ylim = quantile(df$normalized, c(0.01, 0.99), na.rm = T)))
Second example with diamonds dataset.
p<-ggplotly(diamonds %>%
ggplot(aes(cut,price, color = cut)) +
geom_boxplot(outlier.color = NA,outlier.size = 0,outlier.shape = NA))
Then I try with:
ggplotly(df %>%
ggplot(aes(factor, normalized, color = factor)) +
geom_boxplot(outlier.color = NA,outlier.size = 0,outlier.shape = NA) +
coord_cartesian(ylim = quantile(boxplot.stats(df$normalized)$stats[c(1, 5)]*1.5, c(0.01, 0.99), na.rm = T)))
but this way seems to cut my plot y limits and I need a generic solution.