facet-wrap

Create border and title for each column in `facet_wrap`

给你一囗甜甜゛ 提交于 2020-05-11 16:07:24
问题 I want to put black borders with labels and titles around each facet in facet_wrap . Something similar to this: Sample data: library(tidyverse) mtcars %>% mutate(gear = factor(gear, levels = c(4, 3, 5))) %>% ggplot(aes(mpg, disp)) + geom_point() + geom_smooth(method = "lm") + facet_wrap(~am + gear) 回答1: You can do this by manually adding to the ggplot gtable : library(tidyverse) library(grid) library(gtable) p <- mtcars %>% mutate(gear = factor(gear, levels = c(4, 3, 5))) %>% ggplot(aes(mpg,

How to create a facetted plot with title and subtitle specific to each facet?

六月ゝ 毕业季﹏ 提交于 2020-02-22 23:23:11
问题 Generating a plot combined with separate plots for each column with title and subtitles, along with a vertical line for each plot: I have created using the histogram plot for a column with a vertical line. library(ggplot2) library(gridExtra) library(tidyr) actualIris <- data.frame(Sepal.Length=6.1, Sepal.Width=3.1, Petal.Length=5.0, Petal.Width=1.7) # Sepal Length oneTailed <- sum(actualIris$Sepal.Length < iris$Sepal.Length)/nrow(iris) plot1SL <- ggplot(iris, aes(x=Sepal.Length)) + geom

How to create a facetted plot with title and subtitle specific to each facet?

隐身守侯 提交于 2020-02-22 23:22:58
问题 Generating a plot combined with separate plots for each column with title and subtitles, along with a vertical line for each plot: I have created using the histogram plot for a column with a vertical line. library(ggplot2) library(gridExtra) library(tidyr) actualIris <- data.frame(Sepal.Length=6.1, Sepal.Width=3.1, Petal.Length=5.0, Petal.Width=1.7) # Sepal Length oneTailed <- sum(actualIris$Sepal.Length < iris$Sepal.Length)/nrow(iris) plot1SL <- ggplot(iris, aes(x=Sepal.Length)) + geom

Independent color gradient for each facet in facet_wrap() + ggplot2()

放肆的年华 提交于 2020-01-25 07:26:12
问题 I'm struggling to plot a gradient color scale for each facet in facet_wrap() independently. Data is too big to post it here but here is my code: ggplot(stack, aes(hour, day)) + geom_tile(aes(fill = percent), colour = "white") + facet_wrap(~author, ncol = 3) + theme_minimal() + scale_fill_distiller(palette = 'RdYlBu') + theme( axis.title.x = element_blank(), axis.title.y = element_blank(), legend.position = "none", strip.background = element_rect(fill = '#E5E6E1'), strip.text = element_text

Only show one variable label in facet_wrap strip text?

跟風遠走 提交于 2020-01-24 19:18:26
问题 I am plotting multiple graphs using facet_wrap() from the ggplot2 package in R . When facetting by multiple variables, the result includes both labels in the strip text. How can I remove one? In this toy example from the mpg dataset, how to keep the cyl labels only? Thanks ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(c("cyl", "drv")) 回答1: The biggest concern with this is as @aelwan mentioned several plots will have the same strip labels but are not the same. Ignoring this issue, I

Only show one variable label in facet_wrap strip text?

空扰寡人 提交于 2020-01-24 19:18:07
问题 I am plotting multiple graphs using facet_wrap() from the ggplot2 package in R . When facetting by multiple variables, the result includes both labels in the strip text. How can I remove one? In this toy example from the mpg dataset, how to keep the cyl labels only? Thanks ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(c("cyl", "drv")) 回答1: The biggest concern with this is as @aelwan mentioned several plots will have the same strip labels but are not the same. Ignoring this issue, I

facet wrap distorts state maps in R

早过忘川 提交于 2020-01-15 23:25:23
问题 This question is an extension of a previous question I asked, see Mapping different states in R using facet wrap. I want to display points in the maps, colored by their value. I can get this to work using the following code, which produces a decent looking plot, but I like the look of the 'sepStates' output that Mark Peterson provided better. mn <- min(test$value); hist(test$value) mx <- max(test$value) ggplot(map_data('state',region=states), aes(x=long,y=lat,group=group)) + geom_polygon

ggplot2 facet_wrap with mathematical expression

…衆ロ難τιáo~ 提交于 2020-01-13 13:09:06
问题 Using facet_wrap(), I want to label each individual plot with a mathematical expression: library(ggplot2) x <- rnorm(100, 50, 10) y <- rnorm(100, 50, 10) grp <- rep(c("a", "b", "c", "d"), each=25) test.df <- data.frame(grp, x, y) mean.df <- aggregate(test.df[c("x", "y")], test.df["grp"], mean) p <- ggplot(test.df) + geom_point(aes(x=x, y=y, col=grp)) + facet_wrap(~ grp) + geom_text(data=mean.df, aes(x=x, y=y, label=paste("xbar=", round(x,1)))) p I want \bar(x) instead of xbar. I tried

annotate r squared to ggplot by using facet_wrap

岁酱吖の 提交于 2020-01-13 05:55:07
问题 I just joined the community and looking forward to get some help for the data analysis for my master thesis. At the moment I have the following problem: I plotted 42 varieties with ggplot by using facet_wrap: `ggplot(sumfvvar,aes(x=TemperaturCmean,y=Fv.Fm,col=treatment))+ geom_point(shape=1,size=1)+ geom_smooth(method=lm)+ scale_color_brewer(palette = "Set1")+ facet_wrap(.~Variety)` That works very well, but I would like to annotate the r squared values for the regression lines. I have two

annotate r squared to ggplot by using facet_wrap

ぐ巨炮叔叔 提交于 2020-01-13 05:54:02
问题 I just joined the community and looking forward to get some help for the data analysis for my master thesis. At the moment I have the following problem: I plotted 42 varieties with ggplot by using facet_wrap: `ggplot(sumfvvar,aes(x=TemperaturCmean,y=Fv.Fm,col=treatment))+ geom_point(shape=1,size=1)+ geom_smooth(method=lm)+ scale_color_brewer(palette = "Set1")+ facet_wrap(.~Variety)` That works very well, but I would like to annotate the r squared values for the regression lines. I have two