How to use more than 6 shapes in ggplot? - r

I have data that I would like to plot and use shapes to symbolise the data . In total I have 20 potential different pieces of data to be represented by shapes.
e.g they are labeled such as R/Hand elbow, R/Hand knee, R/Hand foot, L/Hand shoulder, L/Hand neck etc etc
So far I keep coming up with a limitation of 6 shapes and they are all different colors.
One option I do have is to not only use shapes but also color code the shapes.
So 10 different shapes with each shape representing a different piece of categorical data, but all shapes being Blue.
and then the same 10 shapes but all shapes begin colored Red.
The 20 pieces of data are locations on the body (10 on the left and 10 on the right).
thanks

You can create your own discrete scale with the scale_manual variants. It this case you will need scale_shape_manual. When you type ?pch you get the help page hich gives the values you can use. In your case, you use for example:
scale_shape_manual(values=1:20, labels=c("R/Hand elbow", "R/Hand knee", "R/Hand foot", "L/Hand shoulder", "L/Hand neck", and so on ...))
However, using 20 different shapes could result in a confusing plot. As you want to distuinghish body parts, you might consider using faceting between for example left and right part of the body.

Related

Making one variable be shapes of different colors (ggplot2)

So right now I've got this plot:
my plot
(sorry it's not inline image, this is my first time on Stack Overflow and it wouldn't let me post images)
The plot is produced with this code:
ggplot(potassium.data,
aes(x=Experiment,y=value,
colour=Pedigree))+geom_jitter()+labs(title=element)
The problem is, there are 31 different maize pedigrees being plotted here, so it's difficult to distinguish the colors from each other. I was wondering if it's possible to make it so that the color and shape of the point are used to uniquely identify a pedigree, so that for example one pedigree is red squares, another is red circles, a third one is blue squares, a fourth is blue circles, and so on. This would make it far easier to distinguish the points. Anyone know how to do this?
I don't think thats possible, if you do the shaping by pedigree you will just end up with as many categories of shapes as you have colors now.
geom_label() and geom_text() would let you plot the cultivar id directly onto the plot, then maybe you could build a separate column for something equivalent to genus, so that the cultivars could be grouped somehow (maybe A, B, PH, etc). Then you could color by that "genus" column, which would make the plot look better:
ggplot(potassium.data,
aes(x=Experiment,y=value, label=Pedigree, colour = genus))+
geom_label(position = position_jitter())+
labs(title=element)
Ideally you would end up with a plot colored by the genus while only plotting the suffix digits currently in Pedigree.
I have to agree with Nathan and Joran, the plot is quite confusing by having so many different points and adding shapes into the mix is unlikely to help.
To answer your question you should be able to use shape=pedigree, but maybe to make the graph more readable you could join the pedigrees from one experiment to the other with a geom_line so the reader spends less time scanning.

How to plot several plots with same legend ggplot2, R

I just came into a problem while making several maps in R, the problem I came to is that I want to plot several maps and some geom_points in those maps, each map will have some points with different values and so the legend with the scales (size and color) will change between maps. All I want is to have exactly the same legend, representing the same values (for both color and size). I've tried with breaks etc but my data is continuous, so I didn't find any way to fix it.
EDIT:Simple example
Will try to explain with simple example by myself. Imagine I have these two arrays to be plotted into different coordinates for 2 different days:
c<-(1,2,3,2,1)
c<-(1,9,2,1,2)
What I want is to set the legend of the plot to be always representing the range 1-9 as values of the geom_points, no matter the specific values of the given day, in a way that no matter the values, the legend will be always the same and if I try to set some slides, the scale will not change
Any ideas?

Chernoff faces extended in R

The aplpack library contains the possibility to plot beautiful Chernoff faces with faces. symbols and TeachingDemos also offer the possibility to plot variations of these faces. But none of them allows to plot more than 15 dimensions (symbols allows two more dimensions for colours, but they are defined in an inconvenient way so that some faces turn out to be completely black, hiding other parts of the face). Is there a way in R (perhaps with another library) to plot more dimensions, e.g. by adding a body with limbs of different lengths or by using colours to visualise some of the dimensions? Maybe I've overseen something and the colours in aplpack can be mapped to variables as well?
The TeachingDemos package also has the ms.face function that works with the my.symbols function to create a scatterplot with the Chernoff Face as the symbol. This gives the original 15 values of the face, plus an x-coordinate and a y-coordinate; with my.symbols you can also specify a color (for the overall face, not individual features) and an overall size based on variables. That gives 19 dimensions, you could also vary the line width and style, but that will probably distort the plot more than help.
With that many dimensions I would probably go more for the star plots (symbols function) with the variables ordered based on a clustering procedure, or use some type of dimension reduction tool (principal components, grand tour, etc.)

R histogram - too many variables

I am trying to illustrate a histogram of 33 different variables. Due to the number of variables I think "beside" different Colors I need to label each bar in a clear way, even using an arrow, if its doable.
I was wondering about
1) How can I define 33 distinct color in R
2) How can I label them, say vertical below X axis with a certain distance from each other to make my figure more clear.
I am using multhist function from Plotrix package, and for data you can image just 33 random vector with different length !
Thanks
As Chris mentioned, trying to distinguish 33 colours doesn't work for humans. You need to find a different plot type that doesn't rely on only colour.
Without a reproducible example, it is not possible to say what this plot should be, but here's some generic colour advice.
Use HCL colours rather the RGB or HSV. Read Escaping RGBland by Achim Zeileis for an explanation. There are some useful functions for generating palettes in the colorspace package.
If your variables are unordered categories (i.e., encoded as factors) then your colours should have different hues. (Use rainbow_hcl.)
If your variables are in some sort of order (ranges or ordered factors) then your colours should have different lightness or chroma. (Use sequential_hcl.) A variation on this is if they differ about some midpoint, in which case you need diverge_hcl.
You can define colors in R in any number of ways; try ?rainbow or ?greyscale for some suggestions
You could also look at all the colors here and just create a vector of your desired colors that you call inside your plot function.
Your problem though is that the human eye and the printing process has trouble distinguishing and reproducing that many distinct colors. See the documentation at the colorbrewer site for more information (and advice on picking colors).
Not sure I understand what your trying to do with the labels, but you can re-label an axis with a call to axis. See the documentation in ?axis.

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