i've this kind of shiny Highcharts function in shiny
h1 <- Highcharts$new()
h1$series(data = test$sites, type="column",name = "Sites Actifs",enabled=T)
h1$series(data = test$alerte, type="column",name = "Sites Alerte")
h1$series(data = test$ID, type="area",name = "CAID", enabled=F)
h1$series(data = test$LD, type="area",name = "MILD")
h1$series(data = test$rat, type="line", name = "Percentile")
h1$series(data = test$epi, type="line", name = "Outbreak")
h1$series(data = test$Temp, type='line', name = "Temperatures")
h1$series(data = test$ND, type = "line", name = "NDVI")
h1$series(data = test$Pm, type="line",name = "Pmm",enabled=T)
h1$colors('rgba(187, 165, 203, 0.9)', 'rgba(187, 40, 175,0.9)','rgba(255,179,128,.9)','rgba(0,0,128,.4)','rgba(170,0,0, .9)', 'rgba(0,0,0, .9)', 'rgba(243,170,80, .9)','rgba(120,193,102, .9)','rgba(85,153,255,.9)')
h1$legend(symbolWidth = 30)
h1$plotOptions(line=list(marker=list(enabled = F)),area=list(marker=list(enabled = F)))
h1$chart(zoomType = "x1")
h1$exporting(enabled = T)
h1$params$width <- 500
h1$params$height <- 700
h1$xAxis(type='datetime', categories=ref_time, tickInterval = 30)
return(h1)
But when i hide some variable (i.e. $sites, $alerte, $Temp) in order to test some hypothesis, if i update another variable (i.e. $rat) all the graph is updated and hidden variables are unhidden.
Do you have a solution to circumvent this "problem"
Thanks
I'm also not sure I understand your problem, but say you define a couple of checkboxes in your shiny app that allow you to hide/show a specific series all you need to do is use that with the visible option, e.g.
h1$series(data = test$ND, type = "line", name = "NDVI", visible=input$show.NDVI)
The plot will still be generated each time you change a checkbox, but the hidden series will stay the same. Another option might be not to add the series in the first place, e.g.
if(input$show.NDVI){
h1$series(data = test$ND, type = "line", name = "NDVI", visible=input$show.NDVI)
}
Related
I am using simple_visNet to represent data but I am not able to add a title to my graph. Any idea?
simu_data_mapper <- mapper.sta(dat = data,
filter_values = filt,
num_intervals = 10,
percent_overlap = 70)
simple_visNet(simu_data_mapper, color_filter = FALSE)
I'm plotting a dynamic network visulisation using the Statnet, networkd3, and ndtv packages.
In the vignette for this package, the authors explain how to "generate interactive html tooltips to be displayed when the vertices are clicked on":
render.d3movie(
toy_epi_sim,
render.par = render.par,
plot.par = plot.par,
vertex.cex = 0.9,
vertex.col = "ndtvcol",
edge.col = "darkgrey",
vertex.border = "lightgrey",
displaylabels = FALSE,
vertex.tooltip = function(slice){paste('name:',slice%v%'vertex.names','<br>',
'status:', slice%v%'testatus')},
output.mode='htmlWidget')
However, I'd like to remove these tooltips, since by default they just show meaningless node IDs, and I'm already showing node labels instead.
Things like vertex.tooltip = F or vertex.tooltip = NA don't work - how do I turn off vertex tooltips?
This is the code I'm using:
render.d3movie(net, usearrows = T, label = "gmv_label",
displaylabels = T,
bg="#ffffff",
edge.col = "#ff0063",
vertex.col = "colo",
vertex.cex = "amount",
edge.lwd = 5,
launchBrowser=T, filename= XXX,
render.par=list(tween.frames = 30, show.time = F),
plot.par=list(mar=c(0,0,0,0)))
I am trying to fit in 13 plots in one image but the plots in the image seem to be stretched and is not clear.
This is currently my coding progress:
par(mfrow=c(4,4))
plot(johordata,series = "male", main = "Johor")
plot(kedahdata,series = "male", main = "Kedah")
plot(kelantandata,series = "male", main = "Kelantan")
plot(melakadata,series = "male",main = "Melaka" )
plot(nsembilandata,series = "male",main = "Negeri Sembilan")
plot(pahangdata,series = "male",main = "Pahang")
plot(perakdata,series = "male",main = "Perak")
plot(perlisdata,series = "male",main = "Perlis")
plot(ppinangdata,series = "male",main = "Pulau Pinang")
plot(sabahdata,series = "male",main = "Sabah")
plot(sarawakdata,series = "male",main = "Sarawak")
plot(selangordata,series = "male",main = "Selangor")
plot(terengganudata,series = "male",main = "Terengganu")
Thus, I'm trying to figure out the right way for the 13 plots to look like this:
As #zx8754 said in the comments, you should use the png or pdf device, to make the result independent of the current scaling of your plots window. See this Q&A. In addition you may want to screw a little more on the par options, e.g. using mar=. Just read ?par help file. Example:
png("X:/plot1.png", width=480, height=480)
op <- par(mfrow=c(4, 4), mar=c(4, 4, 2.5, 1.5)) ## set pars and store defaults
replicate(16, plot(mpg ~ hp, mtcars, col=4))
par(op) ## reset par defaults
dev.off()
I have a question about the par function in R.
I want to change the color and/or width of a line in a graph with par function. (I am using par function because the gaps.plot command below does not allow "col" option to be included. The gaps.plot command is used after the synth command).
So, I used the following command. But I noticed that the lines of the BOX are changed rather than the lines of the GRAPHS.
synth1<-read.csv(file="C:\\Users\\Research\\R\\synthinR_v4.csv",header=TRUE)
attach(synth1)
library("Synth")
dataprep.out34 <- dataprep(foo = synth1, predictors = c("lncdsales", "md1", "md2","md3", "md4", "md5", "md6", "md7", "md8", "md9", "md10", "md11", "yd1", "yd2", "yd3", "yd4", "yd5", "yd6", "yd7", "yd8"), predictors.op = "mean", time.predictors.prior = -13:1, dependent = "lndigital", unit.variable = "artistalbumcode", time.variable = "release", treatment.identifier = 34, controls.identifier = c(1:33, 35:49), time.optimize.ssr = -13:1, time.plot = -13:25)
synth.out34 <- synth(data.prep.obj = dataprep.out34, method = "BFGS")
par(lwd = 2, col="#cccccc")
gaps.plot(synth.res = synth.out34, dataprep.res = dataprep.out34, Ylab = " Log Digital Sales ", Xlab = "Release", Ylim = c(-7, 7) , Main = NA)
Does anyone know how to fix this problem??
Thank you in advance for your willingness to help. I greatly appreciate it!
The col argument to par sets the default plotting colour (i.e. when col is not explicitly specified in plotting calls), but unfortunately col = "black" is hard-coded into the source of gaps.plot.
You can make a modified copy of the function by either (1) viewing the source (F2 in RStudio, or just executing gaps.plot), editing it and assigning it to a new object, or (2) doing something like the following:
gaps.plot2 <- eval(parse(text=gsub('col = "black"', 'col = "red"',
deparse(Synth:::gaps.plot))))
and then using gaps.plot2 as you would use gaps.plot:
gaps.plot2(synth.res = synth.out34, dataprep.res = dataprep.out34,
Ylab = " Log Digital Sales ", Xlab = "Release", Ylim = c(-7, 7) ,
Main = NA)
Alter the lwd similarly. For example to make lines red and have width of 3, use nested gsub calls like this:
gaps.plot2 <- eval(parse(text=gsub('lwd = 2', 'lwd = 3',
gsub('col = "black"', 'col = "red"',
deparse(Synth:::gaps.plot)))))
I have created a two-tab GUI with gWidgets. A graph is embedded in each of the two tabs. The problem is that both graphs are sent to tab 2. How can I switch or choose the active device? The vignette of the gwidgets package suggests either addHandlerChanged or ggraphicsnotebook. In using ggraphicsnotebook, some unwanted buttons are generated. So I am wondering how to do it with addHandlerChanged or other methods. A small example is attached. Thanks.
# library
library(gWidgets); library(cairoDevice)
options(guiToolkit = "RGtk2")
# first tab -----------------------------------------------------------
r.main <- gwindow(title = "Correlation", visible = TRUE)
r.nb <- gnotebook(container = r.main)
rSta <- ggroup(container = r.nb, horizontal = TRUE, label = "Static")
rDyn <- ggroup(container = r.nb, horizontal = FALSE, label = "Dynamic")
ggraphics(container = rSta)
obj.ptNum <- gradio(items = c("100", "1,000", "5,000"),
selected = 2, horizontal = FALSE, container = rSta,
handler = function(h, ...) {plot(1:10, main = "Static graph")})
# second tab -----------------------------------------------
obj.plotNum <- gradio(items = c("10", "50", "300", "400"),
selected = 2, horizontal = TRUE, container = rDyn,
handler = function(h, ...) {
plot(30:35, col = 'red', main = "Dynamic graph")})
ggraphics(container = rDyn)
Edit: I found one solution. Note the problem is not about selecting tab, but about selecting the current active embedded device. For future reference, my code is copied below. One small problem that I cannot figure out: how to show the graph when the application is launched without clicking? Thanks all.
library(gWidgets); library(cairoDevice); library(gWidgetsRGtk2)
library(RGtk2)
options(guiToolkit = "RGtk2")
# first tab -----------------------------------------------------------
r.main <- gwindow(title = "Correlation", visible = TRUE)
r.nb <- gnotebook(container = r.main)
rSta <- ggroup(container = r.nb, horizontal = TRUE, label = "Static")
ggraphics(container = rSta)
staPlot <- function(h, ...) {
sel <- ifelse(test = length(dev.list()) >= 2, yes = 2, no = 1)
dev.set(which = sel)
plot(1:as.numeric(svalue(obj.ptNum)), main = "Static graph")}
obj.ptNum <- gradio(items = c("100", "150", "200"),
selected = 2, horizontal = FALSE, container = rSta,
handler = staPlot)
# second tab -----------------------------------------------
rDyn <- ggroup(container = r.nb, horizontal = FALSE, label = "Dynamic")
dynPlot <- function(h, ...) {
sel <- ifelse(test = length(dev.list()) >= 2, yes = 3, no = 1)
dev.set(which = sel)
plot(1:as.numeric(svalue(obj.plotNum)), col = 'red',
main = "Dynamic graph")}
obj.plotNum <- gradio(items = c("10", "50", "300", "400"),
selected = 2, horizontal = TRUE, container = rDyn,
handler = dynPlot)
ggraphics(container = rDyn)
svalue(r.nb) <- 1
It's bad to use dev.set. If you to create a plot in a graphics device, you can use the following code.
graph <- ggraphics()
visible(graph) <- TRUE
boxplot(...)