ggplot2

Reversing default scale gradient ggplot2

匆匆过客 提交于 2021-02-07 05:13:10
问题 I am newbie, I am trying to desing a heat map. This is my code: ggplot(gd, aes(Qcountry, Q6_1_Q6d), order = TRUE) + geom_tile(aes(fill = prob), colour = "white") + theme_minimal() + labs( y = "Main reason for mobility", x = "Country") + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.3)) + scale_fill_gradient(name = "(%)") Which produces a perfect chart, my problem is low levels are dark blue, and higher values are light blue, which is not intuitive. Most common way to do is

How to add standard error bars to a box and whisker plot using ggplot2?

落花浮王杯 提交于 2021-02-06 12:48:51
问题 I'm trying to add standard error bars to my data similar to the ones seen on the box plots near the end of the answer on this question: https://stats.stackexchange.com/questions/8137/how-to-add-horizontal-lines-to-ggplot2-boxplot I am using the PlantGrowth dataset, which looks like this (except 30 rows long in total): weight group 1 4.17 ctrl 2 5.58 ctrl 3 4.81 trt1 4 4.17 trt1 5 6.31 trt2 6 5.12 trt2 I have produced this plot with the following code ggplot(PlantGrowth, aes(group, weight))+

How to add standard error bars to a box and whisker plot using ggplot2?

心已入冬 提交于 2021-02-06 12:45:48
问题 I'm trying to add standard error bars to my data similar to the ones seen on the box plots near the end of the answer on this question: https://stats.stackexchange.com/questions/8137/how-to-add-horizontal-lines-to-ggplot2-boxplot I am using the PlantGrowth dataset, which looks like this (except 30 rows long in total): weight group 1 4.17 ctrl 2 5.58 ctrl 3 4.81 trt1 4 4.17 trt1 5 6.31 trt2 6 5.12 trt2 I have produced this plot with the following code ggplot(PlantGrowth, aes(group, weight))+

ggplot2, geom_boxplot with custom quantiles and outliers

偶尔善良 提交于 2021-02-06 11:09:51
问题 I have a dataset which includes data from 100 simulations of train runs in a network with 4 trains, 6 stations and lateness at arrival for each train at each station. My data looks something like this: MyData <- data.frame( Simulation = rep(sort(rep(1:100, 6)), 4), Train_number = sort(rep(c(100, 102, 104, 106), 100*6)), Stations = rep(c("ST_1", "ST_2", "ST_3", "ST_4", "ST_5", "ST_6"), 100*4), Arrival_Lateness = c(rep(0, 60), rexp(40, 1), rep(0, 60), rexp(40, 2), rep(0, 60), rexp(40, 3), rep(0

ggplot2, geom_boxplot with custom quantiles and outliers

此生再无相见时 提交于 2021-02-06 11:05:48
问题 I have a dataset which includes data from 100 simulations of train runs in a network with 4 trains, 6 stations and lateness at arrival for each train at each station. My data looks something like this: MyData <- data.frame( Simulation = rep(sort(rep(1:100, 6)), 4), Train_number = sort(rep(c(100, 102, 104, 106), 100*6)), Stations = rep(c("ST_1", "ST_2", "ST_3", "ST_4", "ST_5", "ST_6"), 100*4), Arrival_Lateness = c(rep(0, 60), rexp(40, 1), rep(0, 60), rexp(40, 2), rep(0, 60), rexp(40, 3), rep(0

Getting rid of facet_grid labels on those gray boxes?

荒凉一梦 提交于 2021-02-06 09:48:29
问题 What I'd like it's to remove those labels on the right side, the ones on gray boxes on the side. I'll give an example: p <- ggplot(mtcars, aes(mpg, wt, col=factor(cyl))) + geom_point() p + facet_grid(cyl ~ .) Thanks in advance! Juan 回答1: The following would do that: p <- ggplot(mtcars, aes(mpg, wt, col=factor(cyl))) + geom_point() p <- p + facet_grid(cyl ~ .) p <- p +theme(strip.text.y = element_blank()) Without rectangles p <- ggplot(mtcars, aes(mpg, wt, col=factor(cyl))) + geom_point() p <-

Drawing simple mediation diagram in R

折月煮酒 提交于 2021-02-06 09:08:26
问题 Is there a (preferably easy and straightforward) way to draw simple path diagrams with mediation coefficients in R? I've been looking to DiagrammeR package but that looks like an overkill (and to be honest I failed to figure out how to make a plot). Other options I know of are Dia or Inkscape but those require manual positioning, connecting paths etc. mediation package has a plot option but that draws bootstrapped CIs and what I'd like to achieve is a simple path with coefficients like this

How to perfectly align an unequal number of plots (ggplot2,gridExtra)

醉酒当歌 提交于 2021-02-06 03:30:59
问题 I would like to perfectly align these plots : Here is the R code : library(tidyverse) library(gridExtra) groupes <- tribble(~type, ~group, ~prof, ~var, 1,1,1,12, 1,1,2,-24, 1,2,1,-11, 1,2,2,7, 2,1,1,10, 2,1,2,5, 2,2,1,-25, 2,2,2,2, 2,3,1,10, 2,3,2,3, 3,1,1,10, 3,1,2,-5, 3,2,1,25, 3,2,2,2, 3,3,1,-10, 3,3,2,3, 3,4,1,25, 3,4,2,-18) hlay <- rbind(c(1,2,3), c(1,2,3), c(NA,2,3), c(NA,NA,3)) p1 <- groupes %>% filter(type==1) %>% ggplot(aes(prof,var)) + geom_col() + facet_wrap(~group,ncol=1) + coord

How to perfectly align an unequal number of plots (ggplot2,gridExtra)

与世无争的帅哥 提交于 2021-02-06 03:26:13
问题 I would like to perfectly align these plots : Here is the R code : library(tidyverse) library(gridExtra) groupes <- tribble(~type, ~group, ~prof, ~var, 1,1,1,12, 1,1,2,-24, 1,2,1,-11, 1,2,2,7, 2,1,1,10, 2,1,2,5, 2,2,1,-25, 2,2,2,2, 2,3,1,10, 2,3,2,3, 3,1,1,10, 3,1,2,-5, 3,2,1,25, 3,2,2,2, 3,3,1,-10, 3,3,2,3, 3,4,1,25, 3,4,2,-18) hlay <- rbind(c(1,2,3), c(1,2,3), c(NA,2,3), c(NA,NA,3)) p1 <- groupes %>% filter(type==1) %>% ggplot(aes(prof,var)) + geom_col() + facet_wrap(~group,ncol=1) + coord

Is it possible to draw diagrams in R?

纵饮孤独 提交于 2021-02-05 20:28:18
问题 I was wondering if there is any package in R that could use x, y coordinates and shape sizes to draw something like this: I have the coordinates of vehicles' front centers and their sizes (length and width). Edit This is what the original data set looks like: > head(df) Vehicle.ID Frame.ID Global.X Global.Y Vehicle.Length Vehicle.width Lane Preceding.Vehicle.ID Following.Vehicle.ID Spacing Headway 1 2 43 6451214 1873261 14.5 4.9 2 0 13 0 0 2 2 44 6451217 1873258 14.5 4.9 2 0 13 0 0 3 2 45