Edited to Add: ** I ended up realizing it was a variable type issue, This here is a link to where I finally got it to work!!**
I'm trying to add the adjusted and unadjusted results from a regression onto the same graph, and I'm already using the "model" variable to indicate the number of weeks the regression considers. I'm looking for a way to do a three way distinction, 1= coefficients, 2= number of weeks in model, 3= adjusted/unadjusted. I've gotten it so that everything plots onto one graph, but the adjusted and unadjusted results don't have any legend and are both indicated with the same circle shape and color with no distinction between them. picture of the output without any distinction
I tagged this as ggplot because dwplot visualizes regression model objects or regression results saved in tidy data frames by, e.g., tidy as dot-and-whisker plots generated by ggplot. https://www.rdocumentation.org/packages/dotwhisker/versions/0.5.0/topics/dwplot
I've tried fixing this by having the shape of the plot determined by the third variable, but this failed. Then I tried simply plotting two dwplots on top of each other and failed using either add=TRUE or par(new=TRUE). Does anyone know if this is possible?
The below didn't work, it just resulted in only plotting the second graph.
fig.cur <- dwplot(regression.unadjusted.df,
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = aes(shape = "triangle"))
plot(fig.cur)
par(new = FALSE) #tried with just this line first
#tried with just the add=TRUE second
plot(dwplot(Oregression.adjusted.df, dot_args = aes(shape = "circle")),add=TRUE)
The below didn't work either, it just resulted in the original graph without any distinction by model.adjustment.type
fig.cur <- dwplot(regression.df,
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = model.adjustment.type)))
plot(fig.cur)
I'm attaching the R code I ran, with all of the packages I have loaded in the environment though I didn't use them all for the dwplotting of course, as well as sample data from the regression results. Thanks in advance!
library(tidyverse)
library(magrittr)
library(forcats)
library(lubridate)
library(dotwhisker)
library(ggplot2)
library(zoo)
regression.df <- ( read.csv( 'regression-R-time-series-EXAMPLE.csv', row.names=NULL ))
fig.cur <- dwplot(regression.df,
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = model.adjustment.type)))
plot(fig.cur)
regression.unadjusted.df <- regression.df %>% filter(model.adjustment.type=="unadjusted")
regression.adjusted.df <- regression.df %>% filter(model.adjustment.type=="adjusted")
fig.cur <- dwplot(regression.unadjusted.df,
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = aes(shape = "triangle"))
plot(fig.cur)
par(new = FALSE) #tried with just this line first
#tried with just the add=TRUE second
plot(dwplot(regression.unadjusted.df, dot_args = aes(shape = "circle")),add=TRUE)