Color specification for one group only - r

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 :)

Related

R mapview package show border around groups with same value

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

dygraphs specify color of one series (R)

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 :-)

Create a logarithmic diverging color palette for a treemap in R

I have data that span several orders of magnitude (-10e-9 to 10e+9). I am displaying them on a value treemap, but I want more control over the colors used.
I assume I would want to use the "manual" treemap type, but I have not had much luck with the palette selection / specification. Is there a way to set up a palette in R with the following characteristics?
Diverging, with negative values going from from red (-10e-9) to green (0) and positive values going from yellow (0) to blue (10e+9).
Logarithmic scaling so that the data points closer to zero don't all get assigned nearly-identical colors.
I tried using natural logs of the data for vColor. This produced the visual effect I wanted, but now my legend is displaying log-transformed values, not the original values.
I think you're on the right track. Unfortunately, "manual" treemap assume linear vColor scales.
I will add an argument to change legend break labels. For the time being, you could modify the labels in the plotted grid object.

What is the order of groups in plot.survfit used for color or line types?

I am writing a script that will generate plots of plot(survfit(Surv(time, event)~factor)).
The different survival curves will have a different color. How is the order of the color defined? is it levels(factor)? unique(factor)?
My point is that I would like to automatically script the legend labels and text. Can I safely I use levels(factor) as legend text?
I am sure this is documented somewhere but the help entry of ?plot.survfit is not very helpful?
Yes, the order of the color depends on levels(factor), and yes, you can use levels(factor) for your legend text.
This applies everytime you are dealing with a factor. There is also a number of functions for you to manipulate the levels of your factor if you need so, e.g. check ?relevel.

Finding set of colours that are distinguishable to each other

I am writing a graph plotting program. I thus am looking ways to obtain colours that are distinguishable to each other in order to plot various graphs in one cell.
Is there an algorithm or some website that obtains rgb values that matches this criteria?
EDIT: I am looking for 16 different colours
For an automatic solution, you can take one color as the base color and obtain good matching colors by changing the hue in the HSV/HSB color space. If you need 4 colors for example you could rotate the hue by 90° for each color.
If the number of lines on the graph isn't too large (i.e. you can pick colours by hand), I rather like this (http://colorschemedesigner.com/) for choosing colours that work together, but stand out from each other.

Resources