I am working in Shiny and making an interactive plot with ggplot2. Using pull down menus on the UI the user can change what variables are plotted on the x and y axes. I would like the axes labels on the plot to represent the labels within the pull down menu, not the variable names from the actual dataset. The labels in the pull down menu are easier to interpret.
I can get this to work on my machine by specifying two lists (one for each axis) in the global workspace prior to running my Shiny app.
In the global workspace for one axis
predChoices <- c("Cabezon Standard Length (mm)" = "predlength",
"Cabezon Mass (g)" = "predmass")
and then in the server.R when I specify the axis label in ggplot
scale_x_continuous(paste("\n",names(predChoices[predChoices == input$predVariable])))
where predVariable is the name of the pull-down widget in the UI.R. This code labels the axes nicely with the much more descriptive labels.
The problem is that using this workaround not all the requirements for the Shiny App are included within the app, making it hard to post to the web or share with others, because of the need for the initial code to setup the naming lists within the global workspace.
Is there a means within Shiny of making the axis labels reactive, but allow them to have custom names rather than the actual variable names (from the datafile), without having to make the specification in the global workspace prior to running the app?
Thanks,
Nate
Related
Using avplot in rStudio I created an Added Variable Plot.
I tried to change the name of the x-axis of the separate plots but can't figure out how to change them separately (so that every plot has the correct labelling of the x-axis).
Using xlab I could only change all of them at the same time with the same name.
My goal is to change the df$bis11_survey.Attention into "Attention" and so on.
I don't want to rename them in the data frame, only in the plot if thats's possible.
I added a screenshot of the plot
What command could I use that would let me change them separately?
I want to display a plot in the julia language (using iJulia).
But is doesn't show the plot.
Here is a minimal working example of what I tried:
using Plots
function testplotting()
x=[1,2,3,4]
y1=[1,2,3,4]
y2=[1,2,3,4]
plt=plot(x,y)
plot!(x,y2)
return plt
end
plt=testplotting()
display(plt)
println("finished")`
But is doesn't show the plot..
Without the line where I add the extra line to plot the other array it works, but I want to plot multiple variables at the same time.
Can anyone explain why it doesn't display or how to fix it?
Try plot!(plt, xlabel = "blabla").
plot! with a single argument implicitly modifies the "current" plot, which it gets by querying the current plot in global scope. Given that you are in a function scope, the global scope has no access to the plot you just created. Thus you need to specify which plot you want to modify.
I'm trying to build a .html file via RStudio in to have following function(simplified).
plot1:a simple time series plot of $y_t$, where user can manually pull/drag each dot to change it's values a each time point.
plot2:a time series dependent on $y_t$, such as $f(y_t)=2*y_t+1$, once the value in plot1 changed, the plot2 will also change accordingly.
I want the .html self contained, not cloud based. I'm thinking of plotly, shininy/knitr, but I'm not sure if I'm in the direction or how to connect the dots. Hope anyone can point me to the right direction.
A self-contained/client-side html report sounds well-suited for flexdashboard. It's based on R Markdown, and therefore can accommodate Shiny elements.
I don't know if you can modify values with a mouse, but you can certainly modify values with sliders and other inputs, as well as have a second plot react to a first plot.
You may see some more possibilities in the gallery.
I'm looking for a versatile bubble chart.
In my shiny app it has to be able to adjust to two things:
It must be clickable. I need to read the selected bubble from the chart and use the selected input for other visualisations inside the app.
I have a categorial x-axis.
I was looking into gvisBubbleChart which seemed to fit very well, but it only responds to a numerical x-axis.
For example:
data <- data.frame(id = c(1,2,3,4,5),xvar = c("a","b","c","d","e"),yvar = c(7,2,5,8,1),sizevar = c(3,66,7,8,5),colorvar = rep(0,5))
plot(gvisBubbleChart(data,idvar = "id", xvar = "xvar", yvar = "yvar", sizevar = "sizevar",colorvar="colorvar"))
Changes the xaxis to 1.5:6.0 instead of the string.
Is there a way to work around this? It seems that the input has to be numerical, I could not find a native option to turn this off.
I'm also very open to any other suggested packages which serve my needs, for ggplot I'm not sure if I can make the clickable part work?
So I checked various sources, editing the googlevisBubble chart is possible with a lot of effort, too much for my case as this would be a very hard workaround.
Google Charts Bubble Charts categorical x and y axes instead of numeric
What I'm going to do is use plotly with ggplot for the dynamic input in my shiny app, the hole package looks very promising.
https://plot.ly/r/shinyapp-plotly-events/
I am trying to build an interactive plot. It has properties between a scatterplot and a network - I have a list of nodes and edges (network), but I also would like to constrain the nodes, sometimes on the x-axis sometimes on both x- and y- axis (scatterplot). Finally, I have a text label associated with each node that I would like to display (instead of a dot). I was able to create this using ggplot2.
However, some data sets are too large for this to work without the text labels from each node overlapping. Hence, I would now like to add an interactive feature so that the plot consists of dots representing each node, but that upon UI (such as hovering over a dot), the text label belonging to that dot will be revealed.
I would like to achieve this using R.
I tried animint (https://github.com/tdhock/animint) but it seems to mostly allow interaction between two plots, and here I would like to keep it all in one plot.
I also tried htmlwidgets (http://www.htmlwidgets.org/). I looked at two of their packages: I tried using metricsgraphics (mjs_plot), as it has a show_rollover_text option and mouseover option. However, this package does not allow combination of geoms, and so I could not have both dots (nodes) and lines (edges) represented. I also tried network3D package, but that seems to automatically position nodes so that they are distanced far away from each other, and does not seem to provide options to fix each node on a given x and y location.
I am just looking for advice on any other packages I should maybe consider to solve this problem and/or if I may be missing a feature from a package I already tried that could solve this problem. Thank you.
Maybe identify() will be useful for you. But it works only for base plotting system.
x <- rnorm(300)
y <- rnorm(300)
labs <- seq(300)
plot(x,y)
identify(x,y, labels = labs, plot=TRUE)
identify pic