facet-grid

Free colour scales in facet_grid

青春壹個敷衍的年華 提交于 2020-08-01 18:19:55
问题 Say I have the following data frame: # Set seed for RNG set.seed(33550336) # Create toy data frame loc_x <- c(a = 1, b = 2, c = 3) loc_y <- c(a = 3, b = 2, c = 1) scaling <- c(temp = 100, sal = 10, chl = 1) df <- expand.grid(loc_name = letters[1:3], variables = c("temp", "sal", "chl"), season = c("spring", "autumn")) %>% mutate(loc_x = loc_x[loc_name], loc_y = loc_y[loc_name], value = runif(nrow(.)), value = value * scaling[variables]) which looks like, # > head(df) # loc_name variables

Free colour scales in facet_grid

眉间皱痕 提交于 2020-08-01 18:15:12
问题 Say I have the following data frame: # Set seed for RNG set.seed(33550336) # Create toy data frame loc_x <- c(a = 1, b = 2, c = 3) loc_y <- c(a = 3, b = 2, c = 1) scaling <- c(temp = 100, sal = 10, chl = 1) df <- expand.grid(loc_name = letters[1:3], variables = c("temp", "sal", "chl"), season = c("spring", "autumn")) %>% mutate(loc_x = loc_x[loc_name], loc_y = loc_y[loc_name], value = runif(nrow(.)), value = value * scaling[variables]) which looks like, # > head(df) # loc_name variables

Using facet tags and strip labels together in ggplot2

心不动则不痛 提交于 2020-06-25 21:14:27
问题 I'd like to create a figure using ggplot2 's facet_grid , like below: # Load ggplot2 library for plotting library(ggplot2) # Plot dummy data p <- ggplot(mtcars, aes(mpg, wt)) p <- p + geom_point() p <- p + facet_grid(gear ~ cyl) print(p) This is great, but since it's going in a journal article each panel also needs to be labelled with a, b, c, etc. The package egg has a great function for this called tag_facet , which is used as follows: # Load egg library for tagging library(egg) #> Warning:

ggplot facet_grid x axis stepped

十年热恋 提交于 2020-05-31 04:01:31
问题 I have an issue with aligning categorical x axis labels using facet_grid Its out of alignment and I cannot figure out how to force it to align. my code: ggplot(data=dataset, aes(x=Question)) + facet_grid(~Indicator,scales = "free_x")+ scale_x_discrete(labels = function(x) lapply(strwrap(x, width = 45, simplify = FALSE),paste, collapse="\n"))+ coord_cartesian(ylim = c(20, 90))+ geom_line(aes(y = Result))+ geom_point(aes(y = Result))+ geom_line(aes(y = Result_2))+ geom_point(aes(y = Result_2))+

ggplot - Centralize facet_grid title and appear only once [duplicate]

陌路散爱 提交于 2020-05-29 06:24:06
问题 This question already has answers here : Nested facets in ggplot2 spanning groups (2 answers) Closed 2 months ago . I've created a graph in ggplot with two variables inside facet_grid . I want the title of each facet to repeat only once and in the center of the facet. For example, the zeros and ones in the first raw (upper facet), will appear only once and in the middle. In my original plot, the number of plots per facet is not equal. Thus, patching together two plots using patchwork /

How to add a comparison line to all plots when using Seaborn's FacetGrid

旧时模样 提交于 2020-05-17 08:15:07
问题 I'm trying to add the same comparison line to multiple plots using FacetGrid. Here is where I get stuck: # Import the dataset tips = sns.load_dataset("tips") # Plot using FaceGrid, separated by smoke g = sns.FacetGrid(tips, col="smoker", size=5, aspect=1.5) g.map(plt.scatter, "tip", "total_bill") x = np.arange(0, 50, .5) y = 0.2*x plt.plot(y, x, C='k') plt.show() Here are the results As you can see, the line shows up on the last plot, but not the first. How do I get it on both? 回答1: You can

ggplot: Cover `facet_grid` title with rectangle

倾然丶 夕夏残阳落幕 提交于 2020-04-18 03:46:10
问题 This is an extension/hack to a similar question that I asked here. I Created a graph in ggplot and I want to cover the titles of a facet_grid with a rectangle. Using geom_rect I manged to spread rectangles over each facet. However, how can I spread the rectangles over the titles? Current graph: Expected graph: Sample data and script: library(tidyverse) df <- head(mtcars, 5) plot <- df %>% ggplot(aes(gear, disp)) + geom_bar(stat = "identity") + facet_grid(~am + carb, space = "free_x", scales =

R geom_bar and facet_grid labels on top of bars

随声附和 提交于 2020-03-25 07:33:17
问题 I am trying to make this graph look better, and I'm stuck with the labels (the numbers in this case). How can I make them to show on the top of their correspondent bar? Notice it is a facet_grid. I have the following code and the output: ggplot(articles_europaoccidental_sex_count_unique_group, aes(Country, percentage)) + geom_bar(stat = "identity", position = "dodge", aes(fill=Gender)) + facet_grid(~Propuesta) + geom_text(aes(label = round(percentage, 2)), position = position_dodge(width = 0

Consistent lettering across facets for Tukey letter plot on ggplot

不羁的心 提交于 2020-03-05 03:55:33
问题 I have followed the answer from this question: Tukey test results on geom_boxplot with facet_grid It is great, but what I would like is to compare the facets between them as well. In other words, letter order all of the results first then divide it into facets (I have both horizontal and vertical facets). How can I do this? Also, how can I reorder the letters to start from "a" in the first variable in the first facet, and then "b" the second variable and so on? I tried the following, and it