facet-wrap

How to add mathematical symbols in ggplot facet_wrap text?

拜拜、爱过 提交于 2019-12-11 04:04:42
问题 This question explains how to add mathematical symbols inside a plot. But this doesn't work when the text is supposed to be stored in the data frame itself. This is the case for the text that appears in little boxes of the facet_wrap sub plots. Here is a reproducible example. Let's say for example that I have this data in T and in m³ and that I would like to draw a plot like this one. library(ggplot2) dtf <- data.frame(year = rep(1961:2010,2), consumption = cumsum(rnorm(100)), item = rep(c(

Plotting estimates using ggplot2 & facet_wrap WITHOUT re-fitting models

拥有回忆 提交于 2019-12-11 00:33:45
问题 I am pretty new to ggplot2 and am looking to produce a figure with multiple scatter plots with their respective regression estimates. However I am using non-standard regression approaches (e.g quantile regression and total regression) that are not among the list of method arguments available in geom_smooth() . I have a list of fitted models and corresponding data. Below is a working example. require(data.table); require(ggplot2) N <- 1000 # Generate some data DT <- NULL models <- list() #

facet_wrap and scaling point size

自古美人都是妖i 提交于 2019-12-10 18:29:45
问题 In short: I would like to have separate legends for each "panel" of two-panel plot made using facet_wrap . Using facet_wrap(scales="free") works fine for when I want different axis scales, but not for the size of points. Background: I have data for several samples with three measurements each: x , y , and z . Each sample is from either class 1 or class 2. x and y have the same distributions in each class. However, all the z measurements for class 1 are less than 1.0; z measurements for class

R ggplot facet_wrap with different y-axis labels, one values, one percentages

蓝咒 提交于 2019-12-10 17:52:34
问题 I'm plotting a time series value with its percentages using facet_wrap in ggplot: For the plot below, the upper plot is the value, and the lower plot is percentage change. And I would like the y-axis in the lower plot to be "%". Normally in ggplot I would do something like + scale_y_continuous(labels = scales::percent) But since I'm using facet_wrap, how do I specify that I only want one of the 2 plots' y-axis label to be percentages? P.S. Here is the code to generate this plot: library(data

add “floating” axis labels in facet_wrap plot

末鹿安然 提交于 2019-12-10 15:28:39
问题 I have the same problem as this user - I have a 'jagged' faceted plot, in which the bottom row has fewer panels than the other rows, and I would like to have x-axis ticks on the bottom of each column. The suggested solution for that problem was to set scales="free_x" . (In ggplot 0.9.2.1; I believe the behavior I'm looking for was default in earlier versions.) That's a poor solution in my case: my actual axis labels will be rather long, so putting them under each row will occupy too much room

Switch placement of facet_grid labels

泪湿孤枕 提交于 2019-12-10 11:18:47
问题 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. 回答1: ggplot(data = data, aes(x = obs, y = value, color = factor(id))) +

Segment facet_wrap into multi-page PDF

独自空忆成欢 提交于 2019-12-09 05:08:34
问题 I have searched around for a solution to this, but it appears that most deal with individually generated plots being combined into PDF format, rather than separating out plots generated using faceting onto separate pages of a PDF. Example Data In the above data using the following code, selecting all items in the generated list: Ex<-read.csv("StackOverflowEx (3).csv") library(ggplot2) library(reshape2) vars <- select.list(names(Ex),multiple=TRUE,graphics=TRUE) Cases<-subset(Ex,select=vars) gg

ggplot renaming facet labels in facet_wrap

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 02:31:47
问题 I've hit a stumbling block in writing a ggplot function. I'm trying to change the facet labels in a ggplot facet_wrap plot.... but its proving trickier than I though it would be.... The data I am using can be accessed here str(ggdata) 'data.frame': 72 obs. of 8 variables: $ Season : Factor w/ 3 levels "Autumn","Spring",..: 2 2 2 2 2 2 2 2 2 2 ... $ Site : Factor w/ 27 levels "Afon Cadnant",..: 13 13 13 13 13 13 13 13 13 13 ... $ Isotope: Factor w/ 4 levels "14CAA","14CGlu",..: 1 1 1 1 1 1 2 2

Scales = “free” works for facet_wrap but doesn't for facet_grid

▼魔方 西西 提交于 2019-12-09 02:17:16
问题 I'm trying to understand why the outputs of facet_grid() and facet_wrap() are different, even though the inputs are the same: facet_grid ggplot(temp, aes(x = valor)) + geom_histogram(binwidth = 5, fill = NA, color = "black") + facet_grid(estratificacao ~ referencia, scales = "free") + scale_x_continuous(breaks = seq(0, 100, 10)) + theme_classic() facet_wrap ggplot(temp, aes(x = valor)) + geom_histogram(binwidth = 5, fill = NA, color = "black") + facet_wrap(estratificacao ~ referencia, scales

Need to label each geom_vline with the factors using a nested ddply function and facet wrap

浪尽此生 提交于 2019-12-08 05:06:44
问题 I cannot figure out how to label each vline with year. can someone help? Below is an example of my dataset and code. I would like to label the year on the mean length vline and/or have the same colour code as the year in the figure legend. Sector2 Family Year Length BUN Acroporidae 2010 332.1300496 BUN Poritidae 2011 141.1467966 BUN Acroporidae 2012 127.479 BUN Acroporidae 2013 142.5940556 MUR Faviidae 2010 304.0405 MUR Faviidae 2011 423.152 MUR Pocilloporidae 2012 576.0295 MUR Poritidae 2013