Open Becks-Spake opened 1 year ago
Hi Matt,
Here is some code!! It is already a bit interactive.
mod=bestmod
dat$LUI
min(dat$LUI)
selectInput("VAR1",
label = "Variable 1",
choices = list("Woody",
"LT_clim")
selectInput("VAR2",
label = "Variable 2",
choices = list("Woody",
"LT_clim")
selectInput("SCALE_RESPONSE",
label = "Scale of response variable",
choices = list("Log(species richness)",
"Species richness")
sliderInput("LUI",
label = "LUI_sel",
min = min(dat$LUI), max = max(dat$LUI), value = median(dat$LUI), step = 1),
sliderInput("perc.Clay_sel",
label = "Percentage clay, %",
min = min(dat$perc.Clay), max = max(dat$perc.Clay), value = median(dat$perc.Clay), step = 10),
sliderInput("Bare_sel",
label = "Percentage bare ground, %",
min = min(dat$Bare), max = max(dat$Bare), value = median(dat$Bare), step = 10),
sliderInput("Exotic_grnd_sel",
label = "Percentage cover of exotic species",
min = min(dat$Exotic_grnd), max = max(dat$Exotic_grnd), value = median(dat$Exotic_grnd), step = 10),
# render a plot that displays a classic visreg plot - y
output$cond.plots <- renderPlot({
x <- visreg(fit=mod, xvar=input$VAR1, by=input$VAR2, cond=list(LUI=input$LUI_sel, Exotic_grnd=input$Exotic_grnd_sel, Bare=input$Bare_sel),partial=F, print.cond=TRUE,nn=500, scale="response")# scale = response only if input$SCALE_RESPONSE is richness?? # so need an IF statement here? If log, then omit scale= argument, as it defaults to scale of predictor so log. ALSO - need to specify breaks = c(x, y,z), where x y z are specified low medium high values of VAR2 - how can we do that? currently defaults to a percentile.
condplot <- ggplot(x$fit,aes(VAR1,visregFit))+
geom_line()+
facet_grid(.~VAR2,scales="free")+geom_ribbon(data=x$fit,aes(ymin=visregLwr,ymax=visregUpr),alpha=0.2)+ theme_bw() + theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))+
xlab("VAR2")+ylab("XXXXX")
param.plot1 <- ggplot(dat)+
geom_point(aes(y=LUI, x=input$VAR1))+geom_hline(yintercept=input$LUI_sel, linetype="dashed", col="red")+
xlab("VAR2")+ylab("LUI")###REPLACE - THIS WILL BE DIANA'S NICE PAIRS PLOTS!!!
param.plot2 <- ggplot(dat)+
geom_point(aes(y=Bare, x=input$VAR1))+geom_hline(yintercept=input$Bare_sel, linetype="dashed", col="red")+
xlab("VAR2")+ylab("BARE")### REPLACE - THIS WILL BE DIANA'S NICE N_DIMENSIONAL PLOT!!!
gird.arrange(condplot, param.plot1, param.plot2)
})
week of 14th
Then Matt will make it interactive