Upgraded to version 1.9.2 of Holoviews and now I'm getting the following error:
DataError: None of the available storage backends were able to support the supplied data format. XArrayInterface raised following error:
cannot create a Dataset from a DataArray with the same name as one of its coordinates
The problem happens when trying to aggregate by a categorical field from a panda DataFrame.
hover_opts = hv.opts("QuadMesh [tools=['hover']] (alpha=0 hover_alpha=0.2)")
self._points = hv.Points(df,kdims=[xFieldName,yFieldName])
self._dynamic_hover = datashade(self._points) * dynspread(datashade(self._points, aggregator=ds.count_cat(colorFieldName))) * \
hv.util.Dynamic(aggregate(self._points, width=50, height=50, streams=[RangeXY]),operation=hv.QuadMesh)
If I remove the aggregator I loose the colors on my points but the plot works:
hover_opts = hv.opts("QuadMesh [tools=['hover']] (alpha=0 hover_alpha=0.2)")
self._points = hv.Points(df,kdims=[xFieldName,yFieldName])
self._dynamic_hover = datashade(self._points) * dynspread(datashade(self._points)) * \
hv.util.Dynamic(aggregate(self._points, width=50, height=50, streams=[RangeXY]),operation=hv.QuadMesh)
I just need to give the points colors by this field.
Related
I am trying to complete a network analysis using the function gplot in the package sna. I created an attribute file that includes a column listing the labels I want to show in the figure instead of the NodeName.
VP$Buyer_Relationships$Attributes<- data.frame (NodeName = c(P12, P14, P15, P16), label = c("Bodega", "Bragg", "Cruz", "Angeles"))
sna::gplot(VP$Buyer_Relationships,
gmode="twomode", edge.lwd=edgeweight,
displaylabels=TRUE, label=VP$Buyer_Relationships$Attributes$label, boxed.labels = TRUE
)
But, the figure has labeled the nodes incorrectly. I believe this is because it "defaults to the vertex index number." How do I make it so the nodes show the label I associated with that NodeName?
I am using R version 3.6.0. I have made some biomod models. There is one factor among my environmental variables. When I am trying to create response plots this error comes up:
Error in subinfo == "MinMax" :
comparison (1) is possible only for atomic and list types
The code I use is:
SumGBMs <- BIOMOD_LoadModels(WgBiomodModelOut, models='GBM')
SumGBM_repcurves <- response.plot2(model= SumGBMs ,
Data = WgBiomodModelOut,
show.variables= get_formal_data(WgBiomodModelOut, dem),
fixed.var.metric = 'median',
col = c("blue", "red"),
legend = TRUE,
plot=T)
although I don't think that's the problem, but I have tried to use github biomod2:
devtools::install_github("biomodhub/biomod2", dependencies = TRUE)
but it did not work and the following erro0r showed up:
Error: Failed to install 'biomod2' from GitHub:
(converted from warning) installation of package ‘C:/Users/NP/AppData/Local/Temp/RtmpAtIiba/file70c6f00293b/biomod2_3.4-03.tar.gz’ had non-zero exit status
Can you tell me what goes wrong?
Thanks
I think you are not giving to response.plot2 function what it expects.
Data should be a data.frame with the same explanatory variables than the one used in model fitting process
show.variables should be the name of the explanatory viarable you want to display in the response plot
Maybe something like that will work:
SumGBMs <- BIOMOD_LoadModels(WgBiomodModelOut, models='GBM')
SumGBM_repcurves <- response.plot2(model= SumGBMs ,
Data = get_formal_data(WgBiomodModelOut, 'expl.var'),
show.variables= get_formal_data(WgBiomodModelOut, 'expl.var.names'),
fixed.var.metric = 'median',
col = c("blue", "red"),
legend = TRUE,
plot=T)
Problem:
The add_grid function in the R mapdeck package is very exciting. However, following the CRAN documentation, I cannot seem to get any data to actually plot on the returned map.
In other words, the map returns, but no data is plotted. Is this a known bug?
Code:
library(tidyverse)
library(mapdeck)
# - Enter mapdeck key ... Note that it is user-specific
key <- rstudioapi::askForPassword()
# - Read Example Data Set
df <- read.csv(paste0(
'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/',
'examples/3d-heatmap/heatmap-data.csv'
))
# - Plot Data ... Note how the map returns, but not the data
mapdeck( token = key, style = 'mapbox://styles/mapbox/dark-v9', pitch = 45 ) %>%
add_grid(
data = df
, lat = "lat"
, lon = "lng"
, cell_size = 5000
, elevation_scale = 50
, layer_id = "grid_layer"
)
Created on 2018-09-23 by the reprex package (v0.2.1)
Output:
This is not necessarily a 'bug' inside mapdeck itself, but more the way mapdeck communicates with RStudio. There are conflicts between the different javascript versions they use.
If you open the plot in a browser (by pressing the show in new window button in Rstudio) you should get your plot.
I've got this issue logged, but don't know the way forward yet.
A colleague and I have been trying to set custom legend labels, but so far have failed. Code and details below - any ideas much appreciated!
Notebook: toy example uploaded here
Goal: change default rate values used in the legend to corresponding percentage values
Problem: cannot figure out how to access the legend object or pass legend_kwds to geopandas.GeoDataFrame.plot()
Data: KCMO metro area counties
Excerpts from toy example
Step 1: read data
# imports
import geopandas as gpd
import matplotlib.pyplot as plt
%matplotlib inline
# read data
gdf = gpd.read_file('kcmo_counties.geojson')
Option 1 - get legend from ax as suggested here:
ax = gdf.plot('val', legend=True)
leg = ax.get_legend()
print('legend object type: ' + str(type(leg))) # <class NoneType>
plt.show()
Option 2: pass legend_kwds dictionary - I assume I'm doing something wrong here (and clearly don't fully understand the underlying details), but the _doc_ from Geopandas's plotting.py - for which GeoDataFrame.plot() is simply a wrapper - does not appear to come through...
# create number of tick marks in legend and set location to display them
import numpy as np
numpoints = 5
leg_ticks = np.linspace(-1,1,numpoints)
# create labels based on number of tickmarks
leg_min = gdf['val'].min()
leg_max = gdf['val'].max()
leg_tick_labels = [str(round(x*100,1))+'%' for x in np.linspace(leg_min,leg_max,numpoints)]
leg_kwds_dict = {'numpoints': numpoints, 'labels': leg_tick_labels}
# error "Unknown property legend_kwds" when attempting it:
f, ax = plt.subplots(1, figsize=(6,6))
gdf.plot('val', legend=True, ax=ax, legend_kwds=leg_kwds_dict)
UPDATE
Just came across this conversation on adding in legend_kwds - and this other bug? which clearly states legend_kwds was not in most recent release of GeoPandas (v0.3.0). Presumably, that means we'll need to compile from the GitHub master source rather than installing with pip/conda...
I've just come across this issue myself. After following your link to the Geopandas source code, it appears that the colourbar is added as a second axis to the figure. so you have to do something like this to access the colourbar labels (assuming you have plotted a chloropleth with legend=True):
# Get colourbar from second axis
colourbar = ax.get_figure().get_axes()[1]
Having done this, you can manipulate the labels like this:
# Get numerical values of yticks, assuming a linear range between vmin and vmax:
yticks = np.interp(colourbar.get_yticks(), [0,1], [vmin, vmax])
# Apply some function f to each tick, where f can be your percentage conversion
colourbar.set_yticklabels(['{0:.2f}%'.format(ytick*100) for ytick in yticks])
This can be done by passing key-value pairs to dictionary argument legend_kwds:
gdf.plot(column='col1', cmap='Blues', alpha=0.5, legend=True, legend_kwds={'label': 'FOO', 'shrink': 0.5}, ax=ax)
I am trying to use ggnet2 for visualizing a network analysis, but have run into an error with the vignette.
I can generate a random network,
library(ggnet2)
library(network)
library(sna)
library(ggplot2)
net = rgraph(10, mode = "graph", tprob = 0.5)
net = network(net, directed = FALSE)
# vertex names
network.vertex.names(net) = letters[1:10]
With an output that looks reasonable
>net
Network attributes:
vertices = 10
directed = FALSE
hyper = FALSE
loops = FALSE
multiple = FALSE
bipartite = FALSE
total edges= 28
missing edges= 0
non-missing edges= 28
Vertex attribute names:
vertex.names
No edge attributes
However, when I try to run..
ggnet2(net)
I get an error
Error: Each variable must be a 1d atomic vector or list. Problem variables: 'x', 'y', 'xend', 'yend'
I am not clear on how this error is arising in the vignette as net is a list, and all variables within it are lists. I have checked to ensure that I have all the necessary packages and they are up-to-date as well as the most recent R version.
I just tried ggnetwork and seem to get a similar error.
Any thoughts on why this errors is arising?
The error message says
Error: Each variable must be a 1d atomic vector or list. Problem
variables: 'x', 'y', 'xend', 'yend'
If you do the following
library(ggnetwork)
net <- ggnetwork(net)
class(net$x)
you will find that x is a one column matrix. The same is true for your other components. So doing
net$x <- net$x[,1]
net$y <- net$y[,1]
net$xend <- net$xend[,1]
net$yend <- net$yend[,1]
will change these all to 1d atomic vectors and
ggplot(net, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(aes(linetype = "directed"), color = "grey50")
should work. You can read more about how to make ggnetwork work for prettier graphs.
I had the same issue following the tutorial at briatte.github.io/ggnet.
The issue went away after I updated the 'igraph', 'ggplot', 'intergraph', 'GGally' packages and installed the 'ggnetwork' from source:
install.packages("ggnetwork", type="source").
This was suggested here to fix another issue, but somehow it worked for me on this one. Perhaps you could give it a try.
I think I've found a solution for the issue, at least on my machine. I'm running R 3.4.3 on Win 10, but this is probably not platform-related.
Until now I've had the CRAN version of GGally installed, along with network and sna, just as mentioned in the example, and this setup threw the exact same error mentioned above. I was confused as the original network object doesn't even have members like x, xend, etc. It turned out that these are in fact members of the ggnetwork object, which is created invisibly during the command ggnet() (ggnetwork vignette).
So I've tried installing ggnetwork: install.packages("ggnetwork") along with the source version of ggnet
(devtools::install_github("briatte/ggnet")).
ggnetwork was installed succesfully, but the package couldn't be loaded because it said that ggplot2 is not installed (which I've found strange because it's a package that I use on a daily basis as part of the tidyverse library).
ggnet installation failed for some reason related to packages being already loaded.
I've restarted the R session, tried loading ggnetwork again, which again failed for lack of ggplot2, so I installed ggplot2. I tried once again installing ggnet from source, (this time before any packages were loaded) and it worked.
So, to sum it up:
After restarting the R session:
install.packages("ggnetwork")
install.packages("ggplot2")
devtools::install_github("briatte/ggnet")
I don't know exactly which step did it, but afterwards the example script produced a graph plot, just as it was supposed to:
library(ggnetwork)
library(network)
library(sna)
library(ggnet)
net = rgraph(10, mode = "graph", tprob = 0.5)
net = network(net, directed = FALSE)
network.vertex.names(net) = letters[1:10]
ggnet2(net)