facet

ggplot2: Using gtable to move strip labels to top of panel for facet_grid

二次信任 提交于 2019-11-27 02:56:56
问题 I am creating a graphic using facet_grid to facet a categorical variable on the y-axis. I decided not to use facet_wrap because I need space = 'free' and labeller = label_parsed . My labels are long and I have a legend on the right so I would like to move the labels from the right of the panel to the top of the panel. Here is an example to show where I'm getting stuck. library(ggplot2) library(gtable) mt <- ggplot(mpg, aes(x = cty, y = model)) + geom_point() + facet_grid(manufacturer ~ .,

R: Reorder facet_wrapped x-axis with free_x in ggplot2

↘锁芯ラ 提交于 2019-11-27 02:19:52
问题 I'm trying to use reorder in a facet-wrapped plot that also uses scales = free_x in ggplot2, but the reorder function isn't reordering the x-axis properly. Here's what I'm running: library(ggplot2) df <- read.table("speaking_distribution_by_play.txt", header = F, sep = "\t") ggplot(df, aes(x=reorder(V2, V3), y=V3)) + geom_bar(stat = "identity") + facet_wrap(~V1, ncol = 4, scales = "free_x") + opts(title = "Distribution of Speakers in Shakespearean Drama") + xlab("Speaking Role") + ylab("Words

different size facets proportional of x axis on ggplot 2 r

[亡魂溺海] 提交于 2019-11-27 01:31:31
The following is a situation: group1 <- seq(1, 10, 2) group2 <- seq(1, 20, 3) x = c(group1, group2) mydf <- data.frame (X =x , Y = rnorm (length (x),5,1), groups = c(rep(1, length (group1)), rep(2, length(group2)))) ggplot(mydf, aes(X, Y, group= groups)) + geom_point()+ facet_grid (.~ group) Different facets are scaled by x limits in the following plot: ggplot(mydf, aes(X, Y, group= groups)) + geom_point()+ facet_grid (.~ group, scales = "free_x") As total width of x has meaning, I want to produce facets of different width not only different scale. Thus the expected facet 1's wideth should be

How to order data by value within ggplot facets

允我心安 提交于 2019-11-26 22:59:34
I have the following data frame: library(tidyverse) tdat <- structure(list(term = c("Hepatic Fibrosis / Hepatic Stellate Cell Activation", "Cellular Effects of Sildenafil (Viagra)", "Epithelial Adherens Junction Signaling", "STAT3 Pathway", "Nitric Oxide Signaling in the Cardiovascular System", "LXR/RXR Activation", "NF-κB Signaling", "PTEN Signaling", "Gap Junction Signaling", "G-Protein Coupled Receptor Signaling", "Role of Osteoblasts, Osteoclasts and Chondrocytes in Rheumatoid Arthritis", "Osteoarthritis Pathway", "VDR/RXR Activation", "Axonal Guidance Signaling", "Basal Cell Carcinoma

How to add different lines for facets

孤街醉人 提交于 2019-11-26 22:04:04
I have data where I look at the difference in growth between a monoculture and a mixed culture for two different species. Additionally, I made a graph to make my data clear. I want a barplot with error bars, the whole dataset is of course bigger, but for this graph this is the data.frame with the means for the barplot. plant species means Mixed culture Elytrigia 0.886625 Monoculture Elytrigia 1.022667 Monoculture Festuca 0.314375 Mixed culture Festuca 0.078125 With this data I made a graph in ggplot2 , where plant is on the x-axis and means on the y-axis, and I used a facet to divide the

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 =

How do you add a general label to facets in ggplot2?

点点圈 提交于 2019-11-26 19:33:28
I often have numeric values for faceting. I wish to provide sufficient information to interpret these faceting values in a supplemental title, similar to the axis titles. The labeller options repeat much unnecessary text and are unusable for longer variable titles. Any suggestions? The default: test<-data.frame(x=1:20, y=21:40, facet.a=rep(c(1,2),10), facet.b=rep(c(1,2), each=20)) qplot(data=test, x=x, y=y, facets=facet.b~facet.a) What I would love: The best I can do in ggplot: qplot(data=test, x=x, y=y)+facet_grid(facet.b~facet.a, labeller=label_both) As indicated by @Hendy, similar to: add a

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 =

How to use empty space produced by facet_wrap?

安稳与你 提交于 2019-11-26 16:18:25
问题 I have a faceted plot that forms an n x m grid. By design, the last (bottom-right) cell is always empty, so I'd like to utilize the extra space by adding another ggplot object. My current solution relies on low-level viewport approach, which is not very elegant and requires some hard-coding for position and size. Instead, I assume the empty space is reachable in some other fashion, probably with gridExtra ? Here's a minimal example for n=m=2 . Note that the edges are not aligned properly, so

Fixing the order of facets in ggplot

被刻印的时光 ゝ 提交于 2019-11-26 15:55:45
Data: type size amount T 50% 48.4 F 50% 48.1 P 50% 46.8 T 100% 25.9 F 100% 26.0 P 100% 24.9 T 150% 21.1 F 150% 21.4 P 150% 20.1 T 200% 20.8 F 200% 21.5 P 200% 16.5 I need to plot a bargraph of the above data using ggplot (x-axis -> "type", y-axis -> "amount", group by "size"). When I used the following code, I am not getting the variable "type" and as well as "size" in the order shown in the data. Please see the figure. I have used the following code for that. ggplot(temp, aes(type, amount , fill=type, group=type, shape=type, facets=size)) + geom_bar(width=0.5, position = position_dodge(width