facet-wrap

Switch placement of facet_grid labels

别来无恙 提交于 2019-12-06 06:02:37
How can I change the placement of the labels of facet_grid() without switching the formula? library(plyr) library(ggplot2) data = data.frame(id = 1:10, value = rnorm(100*10)) data = ddply(data, .(id), transform, obs = 1:100) ggplot(data = data, aes(x = obs, y = value, color = factor(id))) + geom_line() + facet_grid(id ~.) In the following picture, I want the panel text to switch from the right to the top of the panel. ggplot(data = data, aes(x = obs, y = value, color = factor(id))) + geom_line() + facet_wrap( ~id, ncol=1) 来源: https://stackoverflow.com/questions/22127120/switch-placement-of

Multiple rows in facet_grid

↘锁芯ラ 提交于 2019-12-06 06:00:47
问题 I have a dataset that looks roughly like this: names = tibble(NAME_2=c("Location1","Location2","Location3","Location4")) dates = tibble(date = seq(as.Date("2015-01-01"), as.Date("2016-12-31"), by="days")) types = tibble(type = c("comment","post")) df <- merge(names,dates) df <- merge(df, types) zero <- seq(from=0, to=200, by=1) df$n <- sample(zero, size=nrow(df), replace=TRUE) Which produces a facet plot like this: ggplot(data = df, aes(x = date, y = n)) + geom_line() + facet_grid(type ~ NAME

ggplot2 facet_wrap with mathematical expression

浪尽此生 提交于 2019-12-06 00:05:34
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 expression(), but I get: "cannot coerce class ""expression"" to a data.frame". Using geom_text(data = mean.df,

How to lengthen specific tick marks in facet gridded ggplot?

北战南征 提交于 2019-12-05 01:18:19
问题 I want longer tick marks for those with labels in a facet grid. So I worked through this attempt and tried to adapt it to facet gridded plots like so: Defining breaks and labels, minor and major: range.f <- range(unique(df1$weeks)) minor.f <- 1 # every 1 week, NOTE: range.f[2] should be divisible by minor.f! major.f <- 5 # every 5 weeks breaks.f <- seq(range.f[1], range.f[2], minor.f) every_nth.lt <- function (x, nth) {x[1:nth != 1] <- ""; x} # (lite version of https://stackoverflow.com/a

How to produce different geom_vline in different facets in R?

感情迁移 提交于 2019-12-04 20:33:33
问题 I am trying to produce 2 different geom_vlines with different colours in 2 different facets of a dataset. I am doing this to highlight means of 2 different facets. Here's the dataset: Pclass Sex Age SibSp Parch Fare Cabin Embarked Survived 3 male 22 1 0 7.25 S 0 1 female 38 1 0 71.2833 C85 C 1 3 female 26 0 0 7.925 S 1 1 female 35 1 0 53.1 C123 S 1 3 male 35 0 0 8.05 S 0 1 male 54 0 0 51.8625 E46 S 0 Here's the code: g<-ggplot(data = train3, aes(x = Age, y = Survived, colour = factor(Pclass))

ggplot2 facet_wrap Error: predicate must be a closure

狂风中的少年 提交于 2019-12-04 07:32:21
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_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats

How can I have a Greek symbol within one of my facet labels?

一世执手 提交于 2019-12-04 04:18:14
问题 I'm trying to create a plot using ggplot2 (v. 2_2.2.1) facet_wrap , and I need to have a Greek symbol in only one facet label (out of five). I have tried to use code posted here on Stack Overflow: R Greek letters and normal letters for facet label in R facet grid How to add expressions to labels in facet_wrap? How can I use grid to edit a ggplot2 object to add math expressions to facet labels? but without any success (getGrob is not working, and that's true also for the mf_labeller). Can

Adding a geom_line to all facets in a facet_wrap plot in R

血红的双手。 提交于 2019-12-03 16:59:30
问题 I'm trying to create a facet_wrap plot that compares four separate lines to a common fifth line; the goal is to have this fifth line appearing on all four of the other facet_wrap plots. Here's my minimal code: library(ggplot2) x = c( 1, 3, 1, 3, 2, 4, 2, 4) y = c( 1, 3, 2, 4, 1, 3, 2, 4) type = c("A","A","B","B","C","C","D","D") data = data.frame(x,y,type) x = c( 4, 1) y = c( 1, 4) type = c("E","E") line = data.frame(x,y,type) ggplot(data, aes(x,y)) + geom_line() + facet_wrap(~type) + geom

How to produce different geom_vline in different facets in R?

非 Y 不嫁゛ 提交于 2019-12-03 13:14:24
I am trying to produce 2 different geom_vlines with different colours in 2 different facets of a dataset. I am doing this to highlight means of 2 different facets. Here's the dataset: Pclass Sex Age SibSp Parch Fare Cabin Embarked Survived 3 male 22 1 0 7.25 S 0 1 female 38 1 0 71.2833 C85 C 1 3 female 26 0 0 7.925 S 1 1 female 35 1 0 53.1 C123 S 1 3 male 35 0 0 8.05 S 0 1 male 54 0 0 51.8625 E46 S 0 Here's the code: g<-ggplot(data = train3, aes(x = Age, y = Survived, colour = factor(Pclass))) g<-g+facet_wrap(~Sex) g<-g+geom_point(size = 4, alpha = 0.2)+ggtitle("Survival by Gender")+theme(plot

Change plot title sizes in a facet_wrap multiplot

北战南征 提交于 2019-12-03 08:32:00
问题 Can any help me change the title text size for these plots. i.e. make them larger? Script ggplot(NMPSCMOR, aes(Length, fill=Year)) + geom_histogram(position="dodge", binwidth=60, colour="black") + xlim(0, 600) + scale_fill_grey(start = 1, end = 0)+ geom_vline(data=ddply(NMPSCMOR, Year~Morphology~Sector2, numcolwise(mean)), mapping=aes(xintercept=Length,color=Year), linetype=2, size=1) + scale_color_grey(start=1,end=0)+ xlab("Length Class") + ylab(expression(paste("Total Count"))) + #( ", m^2,