facet-wrap

Drawing a line down the centre mean of the density plots for EACH facet

梦想与她 提交于 2020-01-04 09:59:02
问题 Aim: I would like to draw a line down the mean for EACH individual facet. I currently have plotted a line for the mean of all facets: ggplot(mexi_sf, aes(FOODEXP)) + geom_density(alpha = 0.1,fill="red",colour="red") + facet_wrap(~ADM1NAME)+xlim(0, 436)+ geom_vline(xintercept=227)+ ggsave("myplot.png") Note: I know 227 is the mean from the summary function. Here's the data that can be imported with: mexi_sf<-read_sf( dsn = getwd() , layer = "MexicoCaseStudy" , stringsAsFactors = FALSE ) 回答1:

Drawing a line down the centre mean of the density plots for EACH facet

隐身守侯 提交于 2020-01-04 09:56:50
问题 Aim: I would like to draw a line down the mean for EACH individual facet. I currently have plotted a line for the mean of all facets: ggplot(mexi_sf, aes(FOODEXP)) + geom_density(alpha = 0.1,fill="red",colour="red") + facet_wrap(~ADM1NAME)+xlim(0, 436)+ geom_vline(xintercept=227)+ ggsave("myplot.png") Note: I know 227 is the mean from the summary function. Here's the data that can be imported with: mexi_sf<-read_sf( dsn = getwd() , layer = "MexicoCaseStudy" , stringsAsFactors = FALSE ) 回答1:

Drawing a line down the centre mean of the density plots for EACH facet

旧时模样 提交于 2020-01-04 09:56:24
问题 Aim: I would like to draw a line down the mean for EACH individual facet. I currently have plotted a line for the mean of all facets: ggplot(mexi_sf, aes(FOODEXP)) + geom_density(alpha = 0.1,fill="red",colour="red") + facet_wrap(~ADM1NAME)+xlim(0, 436)+ geom_vline(xintercept=227)+ ggsave("myplot.png") Note: I know 227 is the mean from the summary function. Here's the data that can be imported with: mexi_sf<-read_sf( dsn = getwd() , layer = "MexicoCaseStudy" , stringsAsFactors = FALSE ) 回答1:

Annotate x-axis with N in faceted plot

梦想与她 提交于 2020-01-04 04:31:16
问题 I'm trying to produce a boxplot of some numeric outcome broken down by treatment condition and visit number, with the number of observations in each box placed under the plot, and the visit numbers labeled as well. Here's some fake data that will serve to illustrate, and I give two examples of things I've tried that didn't quite work. library(ggplot2) library(plyr) trt <- factor(rep(LETTERS[1:2],150),ordered=TRUE) vis <- factor(c(rep(1,150),rep(2,100),rep(3,50)),ordered=TRUE) val <- rnorm(300

ggplot2 facet_wrap Error: predicate must be a closure

蹲街弑〆低调 提交于 2020-01-01 10:44:51
问题 Loaded this up in a new R session. I can't figure out what's wrong. library(ggplot2) ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_wrap( ~ cyl) Error: Error: `predicate` must be a closure or function pointer ls() character(0) Session Info: R version 3.4.2 (2017-09-28) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English

ggplot2 facet_wrap Error: predicate must be a closure

巧了我就是萌 提交于 2020-01-01 10:44:51
问题 Loaded this up in a new R session. I can't figure out what's wrong. library(ggplot2) ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_wrap( ~ cyl) Error: Error: `predicate` must be a closure or function pointer ls() character(0) Session Info: R version 3.4.2 (2017-09-28) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English

ggplot2: Coloring axis text on a faceted plot

六月ゝ 毕业季﹏ 提交于 2019-12-29 06:51:53
问题 I seem unable to correctly color axis text on a faceted plot when the scales parameter is set to "free" . Consider the following dataset: library( ggplot2 ) X <- data.frame( V1 = LETTERS, V2 = runif( 26 ), V3 = rep( c("F1", "F2"), each = 13 ) ) We can plot the data on a single facet, highlighting the letters D, O, T as follows: v <- ifelse( X$V1 %in% c( "D", "O", "T" ), "red", "black" ) g <- ggplot( X, aes( x = V1, y = V2 ) ) + geom_point() + theme( axis.text.x = element_text( color = v ) )

Show multiple histogram using facet_wrap

别等时光非礼了梦想. 提交于 2019-12-25 03:06:01
问题 Sample data df <- data.frame(id = rep(1:6, each = 50), x = rnorm(50*6, mean = 10, sd = 5), y = rnorm(50*6, mean = 20, sd = 10), z = rnorm(50*6, mean = 30, sd = 15)) ggplot(df, aes(x)) + geom_histogram() + facet_wrap(~id) How do I show x, y, z in the same plot for each id in different colours 回答1: It's best to reshape data from wide to long first, and then add a fill aesthetic to map what (i.e. x , y , z ) to different fill colours: library(tidyverse) df %>% gather(what, val, -id) %>% ggplot

Change y limits in ggplot with facet_wrap to mix of log and regular scales

我的梦境 提交于 2019-12-24 13:24:15
问题 I have a dataset that has a wide range of values for one group. Using ggplot's facet_wrap, I would plot the y axis in a log scale for one group (the group that has the widest range of values) and regular axis for the other group. Below is a reproducible example. set.seed(123) FiveLetters <- LETTERS[1:2] df <- data.frame(MonthlyCount = sample(1:10, 36, replace=TRUE), CustName = factor(sample(FiveLetters,size=36, replace=TRUE)), ServiceDate = format(seq(ISOdate(2003,1,1), by='day', length=36),

Add empty plots to facet, and combine with another facet

筅森魡賤 提交于 2019-12-23 17:45:11
问题 Using this SO solution I created a facet with two "empty" plots, with the aim of combining with another group of facet_wrap plots, as shown below. The purpose is to have two y-axis labels for different unit measurements. How can I make the grid layout look like the top image, which produces the arrangement I want, but not the axis labels? This was accomplished with plot_grid with individual plots. My current output does not scale correctly and overlaps the other plots, as seen in the second