I'm currently struggling with adding a border line around groups of regions with the same value regarding a specific variable. More explicitly: I plotted US-counties and used col.regions based on their dma_index (variable). The next step would be to add a line surrounding the areas containing counties with the same value of dma_index, i.e. those which are coloured the same (to make it more visible and make comparison with different variables more easy). Is there any way to accomplish this? Thanks a lot in advance!
Similar question to: R mapview: Point border color by group
Related
My questions is similar to one that's been asked but in a different language. I'm using plotly in python, to build dash web app dashboards and I have graphs with a y-axis range from negative values to positive values. I would like to leave the positive values black, but I would like to change the negative values to be red (preferably with parentheses around them as well, but the red color is the more important item).
From my research, it seems that there is no native way to do this. I'm up for a complicated solution if that's what it takes. When I inspect the element in the web interface, I can see the html code that shows the RGB values for the text of each tick, but I cannot seem to figure out where I can modify the colors independently of the other tick texts. I've started looking for the source file that is used to format these things so that I can potentially add the logic to it.
The similar question is here and it was asked for JavaScript: Plotly - I want to color each X Axis value in different color based on condition
Any help is appreciated.
I'm looping through a spatial feature dataframe and creating hundreds of maps from each column using ggplot2. Depending on the data present in the column, the legend for each map may be a different size, making the plot size different for each map. Although subtle, you can see below that the first map is offset to the left relative to the second map because of the longer label in the legend
I'd like to maintain the size of the plot area (in this case, the map area) so that all the saved maps are consistently sized and lined up when flipping through them. I've looked through questions and answers on here, but all I've been able to find are solutions for how to preserve aspect/ratio of different plots on the same image/document as described here. I'd like to be able to save each map as its own file.
Can anyone give me suggestions about how to keep the plot size consistent regardless of legend width when saving these plots as images using ggplot2?
I am trying to create horizontal bar chart in in R using the plotly package. Due to the length of the legend items I would like for them to show horizontally at the top or bottom of the visual in 2 columns. Is it possible to dictate the number of columns for the legend?
I've been able to place the legend below the x axis successfully using Layout(legend = list(orientation='h')) however regardless of where I put the legend (using the x and y arguments) it is always just one long list. I've seen a github project for creating a multi column legend in js but not r.
Thanks,
This is not possible in a normal way. I think it has its own logic that determines how many place there it is and how many columns it will display then.
So I guess if you make your plot width smaller you could reach the goal that it will just display 2 column.
Also you can try to play around with the margin attribute (https://plot.ly/r/reference/#layout-margin) by setting r and l to 10 e.g.
An other idea could be to make the font-size in legend (https://plot.ly/r/reference/#layout-legend-font-size) bigger, so that it just uses two columns. Hope it helps.
I read the same github page and I thought that it is not possible, but seems to be! I only checked in Python, but I hope this will help in your endeavors in R as well as everyone in Python looking for information. Sadly, there is not a lot of information on Plotly here compared to other packages.
This solved my problem
Setting orientation='h' is not enough. You also have to put the legend items in different legendgroups, if you want them in different columns. Here is an example with legend labels:
fig = go.Figure([
go.Scatter(x=best_neurons_df['Test Size'],
y=best_neurons_df['Training Accuracy Max'],
# You can write anything as the group name, as long as it's different.
legendgroup="group2",
name='Training',
mode='markers',
go.Scatter(x=best_neurons_df['Test Size'],
y=best_neurons_df['Validation Accuracy Max'],
# You can write anything as the group name, as long as it's different.
legendgroup="group1",
layout=dict(title='Best Model Dependency on Validation Split',
xaxis=dict(title='Validation Set proportion'),
yaxis=dict(title='Accuracy'),
margin=dict(b=100, t=100, l=0, r=0),
legend=dict(x=1, y=1.01,xanchor='right', yanchor='bottom',
title='',
orientation='h', # Remember this as well.
bordercolor='black',
borderwidth=1
))
Example image
I am working on a script for plotting volcano plots for a specific number of groups that the user specifies, i.e. if he wants to have five groups colored, the script modifies the data set accordingly with a new column called color. All the other observations that are there shouldn't be highlighted specifically, but be grey.
Is it possible to only specify the color of one group while letting ggplot2 choose all the colors for the other groups available?
I couldn't solve this using scale_color_manual, since it expects values for all groups!
This image demonstrates my problem, all other features except the groups, i.e. the "Features (all)" group should be grey instead of red, however I want ggplot to color all other groups automatically...
Specifying a custom color palette and sorting the color column solved my problem :)
I have a bunch of series I'm graphing with dygraphs, but one of the series is special and I bold it
dySeries("meanOfMeans",strokeWidth = 4) %>%
but if I try
dySeries("meanOfMeans",strokeWidth = 4,color = "black") %>%
it turns every line in the graph black. Is there a way to just set one color?
Alternatively, is there a way to order the series first? right now the special series is showing up last, which means when the number of series changes, the meanOfMeans falls into a different slot, changing it's color. This is distracting.
If it can just be ordered in the first column, this would be a non-issue, because the color wouldn't change. Note that the series is in the first column in the actual data.table itself, but when I add the dySeries() line, it moves to the end.
You'll need to specify the color you want for each variable separately with a dySeries command for each.
As specified on page 20 of the dygraph package manual, "global and per-series color specification cannot be mixed."
https://cran.r-project.org/web/packages/dygraphs/dygraphs.pdf#page=20
As you found, if you specify only one color, regardless of what series it was specified for, dyGraph will color all of your series accordingly. If you specify some colors, but not all, the colors will not be correct.
As for the ordering of variables, variables will appear on the dygraph according to their dySeries command. When using the stacked version, dyOptions(stackedGraph=TRUE), the variable that is specified first will appear on the top, and the last will appear on the bottom.
I hope this helps :-)