I am using plotly to zoom my plots, save to svg and show most interesting intervals to customers. The thing I can't reach - I need to save picture with hover showing values.
For example, I zoomed, I pointed value I need to show, I see values using hover.
But when I press "Download plot" button - It's saved without hover information. Here is what I see in svg:
How can I show values on saved plots?
Here is my example code:
library(plotly)
x <- c(1:100)
random_y <- rnorm(100, mean = 0)
data <- data.frame(x, random_y)
fig <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')
fig
I really don't know any thing about the software/code you are using but as a general logic you have some different approaches to solve this.
1-create a function to take a screenshot of the area you have on screen with those hovering elements and save it as a bitmap image. This is valid just if you don't require to save/download your plot as an svg file.
2- In case you need to export as svg then you have to create a function to observe and get the svg code which is displaying your plot at the moment of hovering, then save the whole stuff as svg file.
3-If what you require is to save the plot as a svg file then it is also possible that the hovering effect along with the code to produce the highlighted content, to be exported inside the svg. The only means most users have t visualize an svg file is via web browser, so when the parts conteining hovering are hovered they will show the effect and the information.
As I said, these are just general logic to try to find out a solution.
Related
I would like to make a Shiny dashboard with e.g. a simple line chart like the one in the top left panel on this website:
https://inflation.ihs.ac.at
I know how to make the plot with ggplot2 and how to make a Shiny dashboard to display the graph (and different versions of it when inputs in the ui are changed).
However, I do not know how to include the vertical line that follows your cursor and how to display labels and values when you hover over certain values.
My question: Is it possible to make a dashboard like this without having knowledge of CSS/Java/some other programming language than R? I looked at the dygraph package which helped me program something similar to the dashboard on the website above but I am not sure if it includes the possibility to make specific adjustments to the hover options provided.
Ideally I would like to be able to specify the detailed hover options (length, width and color of the line and the labels/values, etc.) and still be able to make the original plot with ggplot2 which is obviously not the case if I plot my data using the dygraph package. Is that an option?
Not exactly what you want but close, with rAmCharts4:
library(rAmCharts4)
dat <- data.frame(
x = 1:10,
y = rnorm(10)
)
amLineChart(
data = dat,
xValue = "x",
yValues = "y",
alwaysShowBullets = TRUE,
cursor = list(axes = "x")
)
I have a 3D plot in plotly for R that I want to put into a presentation. Is there a way I can animate the 3D space rotating in some way as a .gif or other from R?
I understand how to make the plot, how to rotate it on my own, and how to publish it on RPubs, but can't figure out how to save it out. Example below.
# build dataframe
df <- data.frame(replicate(3,sample(0:25,50,rep=TRUE)))
# 3d scatterplot
p1 <- plot_ly(df, x = ~X1, y = ~X2, z = ~X3,
type = "scatter3d",
mode = "markers")
p1
Now we have a cool 3D scatterplot in viewer that user can rotate with mouse drags, but I want to save it out to rotate on its own. There is also a 'save to png' button in the viewer, but when I click it, a text box pops up that says "there was a problem saving your image." I'm thinking some kind of loop that saves images out at different viewer angles, then stitches them together? Any ideas appreciated.
I also tried using the orca() command and received the following error:
orca(p1,file="3dplot.png")
Error: The orca command-line utility is required for this functionality.
Not sure what it means.
In the Viewer tab, if you click Export and Save as Web Page... you might get what you want. Remember to use the .html extention
Neither of both options Save to png or orca() are going to work because the save a snapshot of the current angle so you lose the dynamic part.
Best!
I am trying to overlay a heatmap of polygons on my map and then be able to zoom into different parts of it depending on user input.
The code works fine when I remove the heatmap. The user is able to jump around from place to place (based on a dropdown list).
With the polygons it works the first time fully,
the second dropdown choice causes just a map to show with no polygons and the location does not shift,
and the third dropdown choice nothing shows.
output$HMmapstation <- renderLeaflet({
x <- NA
x <- input$HMstation #picking the place to view
x <- leaflet_map %>% setView(preloaded_stations[which(preloaded_stations$name == x),]$longitude,
preloaded_stations[which(preloaded_stations$name == x),]$latitude,
zoom = 14) %>% clearShapes()
x <- x %>% addPolygons(data=polys_dat, color = ~pal(polys_dat#plotOrder),
smoothFactor=.1, stroke = FALSE, fillOpacity = 0.1)
x
})
The leaflet map is created globally above the server and is as follows:
leaflet_map <- (leaflet() %>%
addProviderTiles("OpenStreetMap.BlackAndWhite",
options = providerTileOptions(noWrap = TRUE,minZoom=9)) %>%#~pal(seq(1,537,1))~rainbow(50, start=0,end=.3, alpha = NULL)
setMaxBounds(-0.715485, 51.252031, 0.514984, 51.745313))
I just cant seem to figure out why it would work once and then stop. Especially since without the polygon it works as expected.
Thank you in advance for any direction you can give me.
Leaflet is an amazing addition to R's quiver, I am starting to use it quite a bit at work and at times I also struggle with lost functionality as layers build. I do not have an answer for you working directly in R, but I have a suggestion.
One of the things that I am discovering as I become a Javascript D3 developer is that the last object into a JS visualization is on top.
So this means as you stack polygons, lines, and other objects and data onto a map, it is possible to BLOCK the visibility/functionality of objects below it.
If you are familiar with Javascript, you could open the devtools in chrome and look to see how the layers are being applied to the map.
As you do this, try to think about how R will call out to JS to compile the web graphic it makes and then see if you can re-order something in your R stack, or turn a shape into an outline so that the shape below retains function.
And it is possible after the graphic is "extruded' from R to go in and manually tweak the javascript controlling the features you are using with a lot more control than you have in R itself. I have done some editing on the resulting file set successfully.
There is a LOT more help in working on leaflet in JS directly here and around the web. You may be able to find a quicker answer that way.
The fix ended up being to put the leaflet in a reactive rather than a renderLeaflet.
I also re-ordered based on bethanyP's response so thank you!
At the moment when a data point is clicked, all other data points are shaded. Is there a way to prevent this?
fig = fig.circle(x, y)
Ideally, I would like to increase size of the selected circle instead. Is there an easy why to do so?
Update
Seems we cannot change size... according to here:
Only the visual properties of selection_glyph and nonselection_glyph are considered when renderering. Changing
positions, sizes, etc. will have no effect.
However, we can simulate it using line_width property, it becomes more fun if I combine it with line_dish.
As of Bokeh 0.12.15, you can set nonselection_glyph=None when you call a glyph method, for example:
p.circle(x, y, radius=radii, fill_color="navy",
line_color=None, fill_alpha=0.6,
# this is the new part
nonselection_glyph=None)
I currently have a network plotted with tkplot(). Originally, I was saving these plots as pngs, but they were too compressed and I liked how a screen shot of the tkplot looked. Is there anyway to make the background of the plot white? Instead of the light grey.
A couple points to clarify things.
If the PNG was too crowded, you can create a bigger PNG file, just specify width and height in the png() call. Or you can make the vertices smaller as well.
The purpose of tkplot() is that sometimes it is just easier to hand-adjust vertex coordinates. The idea is that you call tkplot(), adjust the coordinates, query the adjusted coordinates via tkplot.getcoords(), and then use them with plot(), because plot() is just much more flexible than tkplot().
It is actually possible to change the background color in tkplot(), here is how:
library(igraph)
g <- graph.ring(10)
id <- tkplot(g)
tkconfigure(igraph:::.tkplot.get(id)$canvas, "bg"="lightyellow")
In the next version of igraph it will be possible to query the canvas via tkplot.canvas(), so you won't need to use the internal igraph:::.tkplot.get() command for this.
Unfortunately the background color of the canvas is a property of the widget, so when you export the canvas to EPS, it will be ignored. The way to get around this requieres that you plot a big rectangle of the desired color, and place it below the vertices and edges in the canvas. This is definitely possible, but it is just easier to query the coordinates via tkplot.getcoords() and then use plot().
There is no color in the background of tkplot-produced objects. It is designed to output eps-postscript files which are basicall transparent and designed to be overlayed on some other file. Open the output of an exported file in a reader and you will see no color in the background. Here's what you get when your run the example on the tkplot page, save as an eps file and open with Preview.app on a Mac. (You should be able to use Ghostscript or ImageMagick for similar display.)