Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Trying to plot multiple facets of boxplots and label outliers

$
0
0

I have data frame structured like this:

>data
  ID    Element  Location    FirstPt LastPt  First3  First5  First7  First10 Last3 Last5 Last7 Last10
   12     Copper   Alpha        …       …      …        …       …        …     …     …    …     … 
   12     Iron     Alpha        …       …      …        …       …        …     …     …    …     …      
   12     Lead     Alpha        …       …      …        …       …        …     …     …    …     … 
   12     Zinc     Alpha        …       …      …        …       …        …     …     …    …     …       
   12     Mg       Alpha        …       …      …        …       …        …     …     …    …     …       
   12     Ca       Alpha        …       …      …        …       …        …     …     …    …     …       
   234    Copper   Alpha        …       …      …        …       …        …     …     …    …     …         
   234    Iron     Alpha        …       …      …        …       …        …     …     …    …     …         
   234    Lead     Alpha        …       …      …        …       …        …     …     …    …     …         
   234    Zinc     Alpha        …       …      …        …       …        …     …     …    …     …         
   234    Mg       Alpha        …       …      …        …       …        …     …     …    …     …        
   234    Ca       Alpha        …       …      …        …       …        …     …     …    …     … 

The pattern seen above is consistent throughout the data set. There are several hundred individuals with unique ID numbers, and there are a total of 28 Locations in which the individuals are grouped. I will call the columns FirstPt:Last10 my tests. For each test: I want to produce boxplots for each Element with observations grouped by Location. I want one page per test. So there will be 7 panels per page (one for each Element) and 10 pages (one for each test. I am using R notebook, so I am trying to make these show up below the code chunk. Below is what I have so far but it is not working. I am also trying to figure out how to label the outliers on each boxplot (only the values outside of the quantiles) but am not sure how to incorporate that into this code.

data %>% pivot_longer(.,-c(ID,Location), names_to = "Test", values_to = "Value") %>%
  ggplot(aes(x = Location, y = Value, color = Location))+
  geom_boxplot() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.3, hjust = 1)) +
  theme(legend.position = "none",
        axis.title.y = element_blank(),
        axis.title.x = element_blank()) +
  facet_wrap(.~Element)


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>