logo
down
shadow

GGPLOT - two curves in one plot in B_W mode


GGPLOT - two curves in one plot in B_W mode

By : sefi elmaleh
Date : November 19 2020, 12:41 AM
To fix this issue I have the following piece of code, which I am writing to generate a Black and White image for my article in a paper. , (1)
code :
theme(legend.title = element_blank())
scale_colour_manual(values = rep("black", 2))
scale_linetype_manual(values = c("solid", "dashed"))
ggplot(transform(stack(data.frame(aij, bij)), x = xaxis), 
       aes(x = x, y = values, linetype = ind)) +
  geom_line() + 
  theme_bw() + 
  xlab("x ratio") + 
  ylab("Function values") + 
  theme(text=element_text(family="Times New Roman", face="bold", size=12), 
        legend.title = element_blank()) + 
  scale_linetype_manual(values = c("solid", "dashed"))


Share : facebook icon twitter icon
How to plot multiple logistic regression curves on one plot in Ggplot 2

How to plot multiple logistic regression curves on one plot in Ggplot 2


By : manish kharwal
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You're not going to be able to plot the "S" shaped curves that you get with logistic regression because you do not have a continuous variable to plot over. Instead you're only going to be able to plot predicted values and CIs around those predicted values.
Create a column in your data frame that contains ent, corp, and smb.
code :
newdata3<-read.table("clipboard", header=T)
newdata4<-unique(newdata3)[-4,] #different lower limits for smb... removing the second smb LL


newdata4$NewVar<-rep("",length(newdata[,1]))
newdata4$NewVar[which(newdata3$ent==1)]<-"ent"
newdata4$NewVar[which(newdata3$corp==1)]<-"corp"
newdata4$NewVar[which(newdata3$smb==1)]<-"smb"

windows(5,5)
ggplot(newdata4, aes(NewVar, PredictedProb, colour=NewVar)) + geom_point() +
    geom_errorbar(aes(ymin=LL, ymax=UL), width=.1, size=1)
How to plot multiple curves and color them as group using R ggplot

How to plot multiple curves and color them as group using R ggplot


By : Xavier Jose
Date : March 29 2020, 07:55 AM
it should still fix some issue You are going to want to tidy your data first (shown below with tidyr::gather). Then, when you plot, you will want to set your group = ID and color = factor(class) (for discrete colors):
code :
library(tidyr)
library(ggplot2)

df <- structure(list(ID = c(5820350L, 5820364L, 5820378L, 5820392L, 5820425L, 5820426L), 
                 read1 = c(0.3791915, 0.3758676, 0.3885081, 0.3779945, 0.2954782, 0.3376101), 
                 read2 = c(0.3747022, 0.3711775, 0.38239, 0.3729582, 0.2971604, 0.3368173), 
                 read3 = c(0.3729779, 0.3695976, 0.3804273, 0.371491, 0.2973882, 0.3360203),
                 read4 = c(0.3724259, 0.3693112, 0.3797707, 0.3709072, 0.2973216, 0.3359517), 
                 class = c(1L, 2L, 2L, 1L, 3L, 3L)), 
            .Names = c("ID", "read1", "read2", "read3", "read4", "class"), 
            class = "data.frame", row.names = c("1", "2", "3", "4", "5", "6"))

df <- gather(df, reading, value, -c(ID, class))

ggplot(df, aes(x = reading, y = value, color = factor(class))) +
  geom_line(aes(group = ID))
loop to plot several fitted curves in ggplot?

loop to plot several fitted curves in ggplot?


By : Margot Sleiman
Date : March 29 2020, 07:55 AM
To fix this issue You can get the same plot without repeating the same function for each level factor (iso) like this:
code :
ggplot(data=daf,  aes(x=temp, y=diam, colour = iso)) +  
  geom_point() +
  facet_wrap(~iso) +
  geom_smooth(method="nls",
              method.args=list(formula=y ~ thy * exp(thq * (x-thx)^2 + thc * (x - thx)^3), 
                                 start=list(thy=5.4, thq=-0.01, thx=25, thc=0.0008)),
              se = F, 
              size = 0.5)
plot (ggplot ?) smooth + color area between 2 curves

plot (ggplot ?) smooth + color area between 2 curves


By : Flash_flea
Date : March 29 2020, 07:55 AM
seems to work fine Cool question since I had to give myself a crash course in using LOESS for ribbons!
First thing I'm doing is getting the data into a long shape, since that's what ggplot will expect, and since your data has some characteristics that are kind of hidden within values. For example, if you gather into a long shape and have, say a column key, with a value of "inf20" and another of "sup20", those hold more information than you currently have access to, i.e. the measure type is either "inf" or "sup", and the level is 20. You can extract that information out of that column to get columns of measure types ("inf" or "sup") and levels (20, 40, 60, or 90), then map aesthetics onto those variables.
code :
library(tidyverse)

data_long <- data %>%
  as_tibble() %>%
  gather(key = key, value = value, -Nb_obs, -Nb_obst) %>%
  mutate(measure = str_extract(key, "\\D+")) %>%
  mutate(level = str_extract(key, "\\d+")) %>%
  select(-key) %>%
  group_by(level, measure) %>%
  mutate(row = row_number()) %>%
  spread(key = measure, value = value) %>%
  ungroup() %>%
  mutate(level = as.factor(level) %>% fct_rev())

head(data_long)
#> # A tibble: 6 x 6
#>   Nb_obs Nb_obst level   row   inf   sup
#>    <dbl>   <dbl> <fct> <int> <dbl> <dbl>
#> 1      0      35 20        2     2     4
#> 2      0      35 40        2     2     5
#> 3      0      35 60        2     1     6
#> 4      0      35 90        2     0    11
#> 5      0      39 20        8     3     5
#> 6      0      39 40        8     2     6

ggplot(data_long, aes(x = Nb_obst, ymin = inf, ymax = sup, fill = level)) +
  geom_ribbon(alpha = 0.6) +
  scale_fill_manual(values = c("20" = "darkred", "40" = "red", 
      "60" = "darkorange", "90" = "yellow")) +
  theme_light()
data_smooth <- data_long %>%
  group_by(level) %>%
  do(Nb_obst = .$Nb_obst,
     inf_smooth = predict(loess(.$inf ~ .$Nb_obst, span = 0.35), .$Nb_obst), 
     sup_smooth = predict(loess(.$sup ~ .$Nb_obst, span = 0.35), .$Nb_obst)) %>%
  unnest() 

head(data_smooth)
#> # A tibble: 6 x 4
#>   level Nb_obst inf_smooth sup_smooth
#>   <fct>   <dbl>      <dbl>      <dbl>
#> 1 90         35      0           11. 
#> 2 90         39      0           13.4
#> 3 90         48      0.526       16.7
#> 4 90         39      0           13.4
#> 5 90         41      0           13  
#> 6 90         41      0           13

ggplot(data_smooth, aes(x = Nb_obst, ymin = inf_smooth, ymax = sup_smooth, fill = level)) +
  geom_ribbon(alpha = 0.6) +
  scale_fill_manual(values = c("20" = "darkred", "40" = "red", 
      "60" = "darkorange", "90" = "yellow")) +
  theme_light()
How do I combine multiple curves and plot with R and ggplot?

How do I combine multiple curves and plot with R and ggplot?


By : Silver Apps
Date : March 29 2020, 07:55 AM
To fix the issue you can do I would like to simulate a chromatogram by plotting multiple dnorm curves in ggplot similar to this:
code :
ggplot(data.frame(x = 0), aes(x = x)) +
  stat_function(fun = function(x) rowSums(mapply(dnorm, mean = c(0, 1, .5), 
                                                 sd = c(1, .5, 2), MoreArgs = list(x = x)))) + 
  xlim(-5, 5) +
  theme_classic()
Related Posts Related Posts :
  • Using German characters (ü, ö, ä, etc.) in text analysis (R)
  • R JAGS: Dimension mismatch
  • R - How to create a function that accepts a code block as parameter?
  • How do I manually set geom_bar fill color in ggplot
  • How can I get my points to connect in a plot and show a trend with NA values in data?
  • Read SPecific lines of a CSV file in R-language
  • ggplot stacked bar plot from 2 separate data frames
  • auto.arima not parallelizing
  • Histogram of binned data frame in R
  • R rewriting stringmanipulations implemented in loop to the R-way
  • get first entries in rows of list?
  • 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)
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org