facet-wrap

How to change the facet labels in facet_wrap

安稳与你 提交于 2019-12-23 10:48:09
问题 I am using ggplot and facet_wrap to get the required plots. I have to add few things to the labels of each facet or the variable or the name of each facet, just like how we modify the xlab and ylab directly under ggplot. Example: d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + xlim(0, 2) + stat_binhex(na.rm = TRUE) + theme(aspect.ratio = 1) d + facet_wrap(~ color) All I want to do now is to change the label of each facet i,e D,E,F,G,H,I,J to something else. How can I modify

How do I annotate p-values onto a faceted bar plots on R?

匆匆过客 提交于 2019-12-23 05:50:33
问题 I'd like to know if it's possible to annotate p-values at the top of the graph and in between 2 bar plots. In my case, using ggplot2, I have a faceted graph with 2 conditions (Passage and Isolated) and in each condition, there are 3 levels/3 bar graphs (GA, CH, KO). If it's possible, I have some p-values from pairwise comparisons (GA vs CH, CH vs KO, GA vs KO) that I would like to show on the graph itself. My ggplot script is below: #plot dev.new() accentrating_comb <- ggplot(ch_ko_am_comb,

Plot multiple days data of multiple homes in Facet form of ggplot

喜欢而已 提交于 2019-12-23 01:49:19
问题 I have hourly timeseries data of three homes( H1, H2, H3 ) for continuous five days created as library(xts) library(ggplot2) set.seed(123) dt <- data.frame(H1 = rnorm(24*5,200,2),H2 = rnorm(24*5,150,2),H3 = rnorm(24*5,50,2)) # hourly data of three homes for 5 days timestamp <- seq(as.POSIXct("2016-01-01"),as.POSIXct("2016-01-05 23:59:59"), by = "hour") # create timestamp dt$timestamp <- timestamp Now I want to plot data homewise in facet form; accordingly I melt dataframe as tempdf <-

What do '~' and '.' indicate in a facet_wrap() argument

梦想的初衷 提交于 2019-12-23 01:43:16
问题 I've used R for a while now, and still don't know what I'm doing when it comes to using facet_wrap() . Consider this, for exapmle: ggplot(df, aes(x, y)) + geom_bar(stat = "identity") + facet_wrap(~ z) It works, but whenever I use facet_wrap() I end up just trying different permutations of how its argument should be formatted. This is because I have no idea what ~ or . mean in these arguments. Does anyone have a succinct description of what these things are? 回答1: The facet_grid docs state: a

Mapping different states in R using facet wrap

荒凉一梦 提交于 2019-12-19 04:25:47
问题 I am trying to use facet_wrap in ggplot2 to map a different state into each facet of a multi-faceted plot. My code is listed here, where 'dataset' is a data frame containing a variable named 'state', which contains the names of the different states I want mapped by facet. library(maps) library(ggplot2) states <- c('Oklahoma','Arizona','Washington','North Dakota','Michigan','Florida') map <- ggplot(data=datatest) + geom_polygon(data=map_data ('state',region=datatest$state),aes (x=long,y=lat

ggplot2: How can I set axis breaks separately for each facet in facet_wrap?

◇◆丶佛笑我妖孽 提交于 2019-12-18 06:49:43
问题 I would like to modify the breaks and limits of y-axis of each one of the graphs in the facet_wrap. I want for example reduce the breaks for some of them or I want that they start from 0. ggplot(granuControlLw, aes(distance, group=time)) + geom_line(aes(y = D)) + xlab("Distance from the gate (m)") + geom_point(aes(y = D, shape = factor(time)), size=4.5) + theme_bw() + theme(axis.text.x = element_text(size = 15, angle = 90), axis.text.y = element_text(size = 15, angle = 0)) + scale_x

ggplot2 - create different geom_path objects in facets

核能气质少年 提交于 2019-12-13 19:16:41
问题 First I'll say that I am just learning ggplot2 and this was code I inherited from someone else. I'm using facet_wrap to create two graphs side by side. I'm then using geom_path to draw a shape in each graph, but I want a different shape in each one. Right now I can only get the same shape in each graph, or both shapes in both graphs. So basically need to do something to one facet but not the other. This is my truncated code: #variables already defined square1 <- data.frame(x=c(left, right,

Adjust discrete y-axis height to number of segments in facets

a 夏天 提交于 2019-12-13 17:50:36
问题 I'm attempting to plot an overview of interesting segments in different protein sequences faceted by organism. Each facet/organism may contain different numbers of proteins - long black segments. Each protein has a colored overlay of shorter segments of equal length which may overlap - the color signifying the patient group. I first encountered problems with differences in the spacing between the proteins/segments on the y-axes in the different the facets. I managed to solve this with the

faceting based on geom_point when ggplot() empty and multiple shaded geom_rect exist

对着背影说爱祢 提交于 2019-12-13 05:27:52
问题 I am attempting to shade multiple regions of interest on a scatter plot. Based on this answer, I believe I am forced to leave the intial ggplot() call empty, and supplie the geom_rect() calls before the geom_point() call. I have gotten all of this to work. I can not however apply a facet based on data passed to geom_point() . The following correctly plots my data (scatter plot over red and blue regions of different sizes): ggplot() + geom_rect(aes(xmin=885, xmax=1544, ymin=-Inf, ymax=Inf),

r facet_wrap not grouping properly with geom_point

大城市里の小女人 提交于 2019-12-13 02:20:47
问题 I'm struggling with facet_wrap in R. It should be simple however the facet variable is not being picked up? Here is what I'm running: plot = ggplot(data = item.household.descr.count, mapping = aes(x=item.household.descr.count$freq, y = item.household.descr.count$descr, color = item.household.descr.count$age.cat)) + geom_point() plot = plot + facet_wrap(~ age.cat, ncol = 2) plot I colored the faceting variable to try to help illustrate what is going on. The plot should have only one color in