use ggplot2 to plot two lines with ribbons

use ggplot2 to plot two lines with ribbons

By : user2954836
Date : November 22 2020, 10:33 AM
I think the issue was by ths following , Here's how you can add a ribbon. You can, of course, change the formulas for ymin and ymax to suit your needs:
code :
ggplot(df, aes(x=1:length(v), y=v, group=t, colour=t)) + 
  geom_ribbon(aes(ymin=v-0.1*v, ymax=v+0.1*v, fill=t), alpha=0.2) +

Share : facebook icon twitter icon
Use for loop to plot multiple lines in single plot with ggplot2

Use for loop to plot multiple lines in single plot with ggplot2

By : Harrrrold1985
Date : March 29 2020, 07:55 AM
around this issue Instead of ruuning a loop, you should do this the ggplot2 way. ggplot2 wants the data in the long-format (you can convert it with reshape2::melt()). Then split the lines via a column (here Var2).
code :
y <- matrix(rnorm(100), 10, 10)
y_m <- melt(y)

ggplot() +
  geom_line(data = y_m, aes(x = Var1, y = value, group = Var2))
How to combine and modify ggplot2 legends with ribbons and lines?

How to combine and modify ggplot2 legends with ribbons and lines?

By : Eduardo Aguilar Yépe
Date : March 29 2020, 07:55 AM
it should still fix some issue You can use your version to also get the correct linetype, if you put the linetype insidt the aes function. However, your code becomes even more cumbersome that way. Consider reshaping your data before calling ggplot. Then you don't have to worry about the legend at all.
code :
# reshape data ...
new_data$Ta <- Ta
new_data$zero <- 0
dta <- melt(new_data, id.vars="V", measure.vars=c("IlD", "IlL", "Ta"))
dta.lower <- melt(new_data, id.vars="V", measure.vars=c("IlD_fill", "zero", "Ta"))
dta.upper <- melt(new_data, id.vars="V", measure.vars=c("Ta", "IlL", "Ta"))
dta <- cbind(dta, lower=dta.lower$value, upper=dta.upper$value)
dta$name <- factor(NA, levels=c("Illegal landfill owner's\nprofitable ratio\n",
                                "Waste owner's\nprofitable ratio", 
                                "Official tax"))
dta$name[dta$variable=="IlD"] <- "Illegal landfill owner's\nprofitable ratio\n"
dta$name[dta$variable=="IlL"] <- "Waste owner's\nprofitable ratio"
dta$name[dta$variable=="Ta"] <- "Official tax"
ggplot(dta, aes(x=V, y=value, ymin=lower, ymax=upper, 
                color=name, fill=name, linetype=name)) +
  geom_line(size=1.2) + ylim(c(0, Ta*1.5)) +
  geom_ribbon(alpha=.25, linetype=0) +
  theme(axis.text.x = element_text(angle=0, hjust = 0),
        axis.title = element_text(face = 'bold', size = 14),
        title = element_text(face = 'bold', size = 16),
        legend.position = 'right',
        legend.title = element_blank(),
        legend.text = element_text(size = 12),
        legend.key.width = unit(2, 'cm'))+
  scale_linetype_manual(values=c(4, 5, 1)) +
  labs(title="Profitable ratio between the volume \nof illegally disposed waste \nand costs of illegal waste disposure",
       x="Waste volume, cubic meters",
       y="Cost per cubic meter, RUB")
How to plot multiple lines quickly in R using plot or ggplot2

How to plot multiple lines quickly in R using plot or ggplot2

By : Dr House
Date : March 29 2020, 07:55 AM
around this issue Here is a version using melt from reshape2 and dplyr to fit adjust the data:
code :
n <- 4
df <-
    Ind = 1:n
    , vol_1 = rnorm(n)
    , vol_2 = rnorm(n)
    , vol_3 = rnorm(n)
    , vol_4 = rnorm(n)

melted <-
  melt(df, id.vars = "Ind") %>%
  mutate(Time = as.numeric(gsub("vol_","",variable)))

       , aes(x = Time
             , y = value
             , col = as.factor(Ind))) +
How to plot fitted meta-regression lines on a scatter plot when using metafor and ggplot2

How to plot fitted meta-regression lines on a scatter plot when using metafor and ggplot2

By : sharkshy
Date : March 29 2020, 07:55 AM
around this issue In the documentation for rma.uni of the package metafor it says:
code :
ggplot(dat, aes(x = ablat, y = yi, size = 1/vi, col = alloc))+
  geom_point(data = dat, shape = 16) + 
  geom_line(data = dat,aes(x = ablat,y = preds$pred, size = 1))
ggplot2: standard error ribbons not matching the plot lines

ggplot2: standard error ribbons not matching the plot lines

By : Jan
Date : March 29 2020, 07:55 AM
Hope this helps Specifying the data frame and subsetting to a variable (e.g. with $) can cause weird things to happen in ggplot. You never need such subsetting, as the data frame is already specified to a data parameter at some point (likely in the first ggplot(...) call). Data, like aesthetics, is inherited from ggplot to geoms and stats, too, so unless you're changing the data, there is no reason to worry about re-specifying its origin. (If you do want to change the data frame used, specify the data parameter of the relevant geom or stat.)
Dropping the m$s will fix the problem. Rearranging and simplifying so the logic is more obvious,
code :

m <- data.frame(sound = c("English", "English", "English", "English", "Silence", "Silence", "Silence", "Silence"), 
                `Reading condition` = c("normal", "normal", "trailing mask", "trailing mask", "normal", "normal", "trailing mask", "trailing mask"), 
                diff = c("Difficult questions", "Easy questions", "Difficult questions", "Easy questions", "Difficult questions", "Easy questions", "Difficult questions", "Easy questions"), 
                Mean = c(0.283, 0.36, 0.183, 0.227, 0.19, 0.347, 0.197, 0.333), 
                SD = c(0.500558971667007, 0.34814947033031, 0.497195715406262, 0.447163568809774, 0.49804988833968, 0.361515576848703, 0.498812908487118, 0.373926502247132), 
                SE = c(0.100111794333401, 0.0696298940660619, 0.0994391430812524, 0.0894327137619548, 0.099609977667936, 0.0723031153697406, 0.0997625816974236, 0.0747853004494263), 
                check.names = FALSE)

ggplot(m, aes(x = sound, y = Mean, ymax = Mean + SE, ymin = Mean - SE, 
              color = `Reading condition`, fill = `Reading condition`, 
              group = `Reading condition`)) + 
    geom_line() +
    geom_point() + 
    geom_ribbon(alpha = 0.15, colour = NA) +
    facet_grid(. ~ diff)
Related Posts Related Posts :
  • Conditionally removing rows from a matrix in R
  • Using a loop to find P(-1.5<Y<1.5) for a range of sample sizes
  • R-Count and list the maximum count row by row
  • Include Iverson Bracket in R documentation
  • update a data frame and environment in R
  • How to write dynamic cumulative multiple in R
  • format time using as.POSIX in R
  • Change the class of multiple columns
  • Remove period and spaces within column headings nested in a list of data frames
  • R: error message --- package error: "functionName" not resolved from current namespace
  • labels with geom_text ggplot2
  • Passing mongodb ISODate in R
  • Importing "csv" file with multiple-character separator to R?
  • Change row names of a table obtained from a lm regression using xtable function
  • R language iterate over R object
  • How do you delete the header in a dataframe?
  • Re coding in R using complicated statement
  • accumulating functions and closures in R
  • How do you combine two columns into a new column in a dataframe made of two or more different csv files?
  • Twitter authentication fails
  • Summing Values of One Vector Conditional on Values of Another Vector
  • draw cube into 3D scatterplot in RGL
  • lme4 translate formula to code in 3-level model
  • How to draw single axis plot in R
  • Combine geom_tile() and facet_grid/facet_wrap and remove space between tiles (ggplot2)
  • Use snpStats with R version 3.0.1
  • Makefile gives strange error while compiling markdown file into .docx file
  • How to determine whether a points lies in an ellipse
  • Summarize data already grouped in r
  • Is the bigvis package for R not available for R version 3.0.1?
  • Operator overloading in R reference classes
  • How to enable user to switch between ggplot2 and gVis graphs in R Shiny?
  • Is there an easy way to separate categorical vs continuous variables into two dataset in R
  • Correct previous year by id within R
  • Installation of rdyncall package for R
  • ggplot2 plot that evaluates the percentage and mean of a third variable at intersecting points
  • Error Handling with Lapply
  • data.table - split multiple columns
  • How to compute the overall mean for several files in R?
  • R: Graph Plotting: Subscripts in the legend like LaTeX
  • Restructuring data in R
  • Distance of pointsfrom cluster centers after K means clustering
  • R incorrect value of date function
  • Package "Imports" not loading in R development package
  • r - run a user defined function several times by taking column elements as parameters
  • Create input$selection to subset data AND radiobuttons to choose plot type in Shiny
  • Generate crosstabulations from dataframe of categorical variables in survey
  • Restructure output of R summary function
  • New behavior in data.table? .N / something with `by` (calculate proportion)
  • search certain number vector in R
  • R version doesn't support quartz graphic device - RStudio won't plot
  • Referencing a function parameter in R
  • How to synchronize signals using a cross-correlation and FFT in R?
  • Plotting coefficients and corresponding confidence intervals
  • passing expressions to curve() within a function
  • More effective merging of matched column with duplicates in data.table
  • Easy way to export multiple data.frame to multiple Excel worksheets
  • R Foreach Iterator - Walkforward
  • Table format and output in R
  • Restructuring data and duplicating rows in R
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org