Created
July 18, 2018 00:24
-
-
Save bhive01/b0f11d611996c3f64ae281f613b65092 to your computer and use it in GitHub Desktop.
RHelp_gardenTrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(openxlsx) | |
library(readxl) | |
library(Hmisc) | |
library(tidyverse) | |
#write out the iris dataset | |
# write.xlsx(iris, "iris.xlsx") just to show you how | |
# read in a dataset from excel | |
iris2 <- read_excel("iris.xlsx") # this assumes it's in R's working directory (the one it boots up with) | |
glimpse(iris2) # let's take a look at the structure | |
# note each individual is on its own line, each "trait" is a column | |
ggplot(data = iris2, aes(x = Species, y = Sepal.Length, colour = Species)) + #set up what everything is for plot | |
stat_summary(fun.data = "mean_cl_boot") # compute confidence interval using raw data and bootstrap mean, uses Hmisc package | |
ggsave("single_trait_plot.png") #save it out | |
#what if I want to plot all of the traits? | |
# we need to reshape the data further using tidyr::gather() | |
iris2 %>% | |
gather(data = ., key = Trait, value = Value, -Species) %>% #gather up the traits into a Trait column, put the numbers into the value column and keep species to the side | |
ggplot(data = ., aes(x = Species, y = Value, colour = Species)) + | |
stat_summary(fun.data = "mean_cl_boot") + | |
facet_wrap(~Trait, scales = "free_y", nrow = 2, strip.position = "bottom") # facet by Trait, 2 rows and put labels on the bottom | |
ggsave("faceted_plot.png") #save it out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment