facet-wrap

facet_wrap add geom_hline

北城以北 提交于 2019-11-27 16:06:12
I have the following code for my ggplot - the facet_wrap function draws out 20 plots on the page for each Name and there are 5 Pcode along the x-axis. I would like to calculate the average TE.Contr for each Name and plot that value as a horizontal line on each of the plots (which are split out by Facet_wrap). Currently my codes plots the average of ALL TE.Contr. values instead of the average TE.Contr. of the specific Name. T<-ggplot(data = UKWinners, aes(x = Pcode, y = TE.Contr., color = Manager)) + geom_point(size =3.5)+ geom_hline(aes(yintercept = mean(TE.Contr.))) T<-T + facet_wrap(~ Name,

geom_tile and facet_grid/facet_wrap for same height of tiles

旧巷老猫 提交于 2019-11-27 09:05:38
Using ggplot, I would like represent a graph tile with panel, but with same height tile for each panel. I have this graph : dataSta <- list(sites=rep(paste("S", 1:31),each=12), month=rep(1:12,31), value=round(runif(31*12, min=0, max=3000)), panel=c(rep("Group 1",16*12),rep("Group 2", 12*12), rep("Group 3", 3*12))) library(ggplot2) library(grid) base_size <- 9 windows() ggplot(data.frame(dataSta), aes(factor(month), sites)) + geom_tile(aes(fill = value), colour = "black")+ facet_wrap(~panel, scale="free_y", nrow=3)+ theme_grey(base_size = base_size) + labs(x = "",y = "") + scale_x_discrete

ggplot2: Problem with x axis when adding regression line equation on each facet

左心房为你撑大大i 提交于 2019-11-27 07:16:29
问题 Based on the example here Adding Regression Line Equation and R2 on graph, I am struggling to include the regression line equation for my model in each facet. However, I don't figure why is changing the limits of my x axis. library(ggplot2) library(reshape2) df <- data.frame(year = seq(1979,2010), M02 = runif(32,-4,6), M06 = runif(32, -2.4, 5.1), M07 = runif(32, -2, 7.1)) df <- melt(df, id = c("year")) ggplot(data = df, mapping = aes(x = year, y = value)) + geom_point() + scale_x_continuous()

Flip facet label and x axis with ggplot2

荒凉一梦 提交于 2019-11-27 06:24:04
问题 I am looking to flip the labels on a faceted panel of 1 row and 5 columns, so that the facet headers appear on bottom, and the x axis appears on top of facets. The reason is that I want to reuse those headers for a table that will be directly below the graph. So in this example... library(ggplot2) my.hist<-ggplot(diamonds, aes(clarity)) + geom_bar() my.hist + facet_wrap( ~ cut, ncol=5) + coord_flip() I would want the "cut" labels to show up below the chart. I was thinking that facet_grid

Add x and y axis to all facet_wrap

青春壹個敷衍的年華 提交于 2019-11-27 05:32:43
问题 It is often desirable to minimize ink in a plot. I have a faceted plot ( facet_wrap ) and would like to remove as much ink as possible yet maintain readability. I have set it up as I'd like except the x and y axis is not present for the facets (subplots) unless on the far left or bottom. With so much ink removed I believe the eye needs these cues and am asking how to put the x and y axis in all plots within a facet_wrap . Below is my code thus far, the current output and the deired output

ggplot2: Splitting facet/strip text into two lines

那年仲夏 提交于 2019-11-27 03:16:21
问题 Consider the following ggplot2 graph with long facet/strip text broken in two lines. The text goes outside the area devoted to facet titles. library(ggplot2) x <- c(1:3, 1:3) y <- c(3:1, 1:3) grp <- c(0, 0, 0, 1, 1, 1) p <- qplot(x=x, y=y) + geom_line() + facet_wrap(~ grp) grob <- ggplotGrob(p) strip.elem.y <- grid.ls(getGrob(grob, "strip.text.x", grep=TRUE, global=TRUE))$name grob <- geditGrob(grob, strip.elem.y[1], label="First line and\n second line" ) grid.draw(grob) Is there a way to

Setting absolute size of facets in ggplot2

不问归期 提交于 2019-11-26 22:45:33
I'm creating several facetted plots for a report. The number of facets varies between 2 and 8. Ideally, I'd like the absolute size of each facet (across plots) to be the same (e.g. 4x4 cm) so that it is easier to compare them (and it looks nicer, too). Is that possible? df1 <- structure(list(group1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,1L, 1L, 1L, 1L, 1L), .Label = c("S1", "S2"), class = "factor"), group = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("A", "B", "C", "D", "E"), class = "factor"), value = 1:12), class = "data.frame", row.names = c(NA, -12L), .Names =

ggplot2: facet_wrap strip color based on variable in data set

↘锁芯ラ 提交于 2019-11-26 21:31:33
Is there a way to fill the strips of facets created with facet_wrap based on a variable supplied with the data frame? Example data: MYdata <- data.frame(fruit = rep(c("apple", "orange", "plum", "banana", "pear", "grape")), farm = rep(c(0,1,3,6,9,12), each=6), weight = rnorm(36, 10000, 2500), size=rep(c("small", "large"))) Example plot: p1 = ggplot(data = MYdata, aes(x = farm, y = weight)) + geom_jitter(position = position_jitter(width = 0.3), aes(color = factor(farm)), size = 2.5, alpha = 1) + facet_wrap(~fruit) I know how to change the background color of the strips (e.g. to orange): p1 +

Place a legend for each facet_wrap grid in ggplot2

旧时模样 提交于 2019-11-26 20:08:46
I have this data frame: Date Server FileSystem PercentUsed 1 12/1/2011 A / 60 2 1/2/2012 A /var 50 3 2/1/2012 A tmp 90 4 2/10/2012 A /db 86 5 2/13/2012 A /app 90 6 12/1/2011 B C: 67 7 1/2/2012 B D: 67 8 2/1/2012 B F: 34 9 2/10/2012 B /restore 89 10 2/13/2012 B G: 56 11 12/1/2011 C / 90 12 1/2/2012 C /tmp 78 13 2/1/2012 C /data 67 14 2/10/2012 C /Storage 34 15 2/13/2012 C /database 12 dput(x) structure(list(Date = structure(c(2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L), .Label = c("1/2/2012", "12/1/2011", "2/1/2012", "2/10/2012", "2/13/2012"), class = "factor"), Server =

facet_wrap add geom_hline

我的未来我决定 提交于 2019-11-26 17:24:51
问题 I have the following code for my ggplot - the facet_wrap function draws out 20 plots on the page for each Name and there are 5 Pcode along the x-axis. I would like to calculate the average TE.Contr for each Name and plot that value as a horizontal line on each of the plots (which are split out by Facet_wrap). Currently my codes plots the average of ALL TE.Contr. values instead of the average TE.Contr. of the specific Name. T<-ggplot(data = UKWinners, aes(x = Pcode, y = TE.Contr., color =