R: order top 10 of result "means" and output results as .csv -
i have database: link
fun_mean <- function(x){return(round(data.frame(y=mean(x),label=mean(x,na.rm=t)),digit=2))} foo <- qplot(interest, scored.probabilities, data = dataset1, geom = "boxplot"); foo <- foo+stat_summary(fun.y = mean, geom="point",colour="darkred",size=3)+stat_summary(fun.data = fun_mean,geom="text", vjust=-0.7) ggsave(foo, file="interest.png", width=20, height=7)
there mach information, want top 10 mean values (output new .png) , output mean value table .csv?
thank you.
a dplyr
solution
library(dplyr) fun_mean <- function(x){return(round(data.frame(y=mean(x),label=mean(x,na.rm=t)),digit=2))} m <- dataset1 %>% group_by(interest) %>% summarize(y=mean(scored.probabilities), label=mean(scored.probabilities,na.rm=t)) %>% arrange(desc(y)) idx <- as.character(m$interest[1:10]) dataset2 <- filter(dataset1,interest %in% idx) foo <- qplot(interest, scored.probabilities, data = dataset2, geom = "boxplot"); foo <- foo + stat_summary(fun.y = mean, geom="point",colour="darkred",size=3) + stat_summary(fun.data = fun_mean,geom="text", vjust=-0.7) +
Comments
Post a Comment