![]() ![]() But some prefer Edward Tufte’s approach of maximizing the “Data/Ink Ratio”- that is, dropping borders, grids, and axis lines. I don’t have terribly strong opinions about these choices (I’m pretty happy with ggplot2’s theme_bw()). A simple proxy for this is to order by “% who spend % mutate ( Task = reorder ( Task, Percentage, function ( e ) e )) %>% ggplot ( aes ( Hours, Percentage )) + geom_bar ( stat = "identity" ) + facet_wrap ( ~ Task ) + geom_text ( aes ( label = paste0 ( Percentage, "%" ), y = Percentage ), vjust = 1.4, size = 5, color = "white" ) + theme ( = element_text ( angle = 90, hjust = 1 )) + xlab ( "Hours spent per week" )įrom here, the last step would be to adjust the colors, fonts, and other “design” choices. I like to give them an order that makes them easier to browse- something along the lines of. The ordering of task facets is arbitrary (alphabetical in this plot). ggplot ( d, aes ( Hours, Percentage )) + geom_bar ( stat = "identity" ) + facet_wrap ( ~ Task ) + geom_text ( aes ( label = paste0 ( Percentage, "%" ), y = Percentage ), vjust = 1.4, size = 5, color = "white" ) readr::read_csv is useful for constructing a table on the fly: library ( readr ) d 4 a dayīasic exploratory data analysis,11,32,46,12Įxtract/transform/load,43,32,20,5" ) # reorganize library ( tidyr ) d 4 hours a day on it!”) So I add a geom_text layer. ![]() ![]() I start by transcribing the data directly from the plot into R. (I’d note that this post is appropriate for Pi Day, but I’m more of a Tau Day observer anyway). This also serves as an example of the thought process I go through in creating a data visualization. So here I’ll show how I would have created a different graph (using R and ggplot2) to communicate the same information. The problem with a lot of pie-chart bashing (and most “chart-shaming,” in fact) is that people don’t follow up with a better alternative. But at a glance, do you have any idea whether more time is spent “Presenting Analysis” or “Data cleaning”? We’re meant to compare and contrast these six tasks. But this is an especially unfortunate example. Pie charts have a bad reputation among statisticians and data scientists, with good reason ( see here for more). But I was disappointed that in an article about data scientists (!) they would include a chart this terrible: Narasimhan gave insightful and well-communicated answers, and I both recognized familiar opinions and learned new perspectives. I wasn’t disappointed in the interview: General Electric’s Dr. The title intrigued me immediately, partly because I find myself explaining that same topic somewhat regularly. Labs(title = paste("Question:", as.Yesterday a family member forwarded me a Wall Street Journal interview titled What Data Scientists Do All Day At Work. Pie_chart(data, main = "choice", labels = NULL, condition = "dilemma", stat_title = "dilemma x choice") + ![]() So I was wondering if the next release of ggplot2 would possibly contain functionality to handle percentages labels for a pie chart.Ĭhoice_pie <- plyr::dlply(fmri_md. Changing the equation for the position labels ( label_pos = sum(perc) - cumsum(perc) + perc / 2) inevitably messes up one of the conditions. P <- p + labs(subtitle = chi_subtitle(jmv::contTables(df2, rows = 'col1', cols = 'col2', phiCra = TRUE),Īs you can see, it works fine for some conditions, but not for other. P <- p + facet_wrap(condition, labeller = "label_both") # reorder the category factor levels to order the legendĭf] % dplyr::select(condition, main) # if it doesn't work, try toying with the formula for the label_pos to get the desired result # label_pos is a tricky variable to define.the one here will work fine in most, but not all, cases # the chi-square test presented.if not entered, the default will be "Chi-square test"ĭplyr::mutate(perc = counts / sum(counts)) %>%ĭplyr::mutate(label_pos = sum(perc) - cumsum(perc) + perc / 2, # effect is the text label that needs to be entered to denote which interaction effect is being investigated in # custom function to write results from chi-square test into subtitle for the plot ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |