Is there a way you can create a scatter graph in R and colour the points by a category? For example, I have a dataset with a list of x and y points (both columns 'Xpoints' and 'Ypoints' have scales from 0 to 100), but each combined x&y point belongs to one of five categories (in a third column 'Category'). I would like to plot all the combined x&y points AND colour each point by its respective category. I'm guessing that the five categories would have to allocated numbers 1 to 5 in an additional column. But what would be the code to plot this?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
That is a really easy task for the graphical package
Lattice
. It is designed especially for multivariate analysis, that can handle really easily. I load the datasetiris
to provide an example.Lattice
allows immediate multifacet plots, showing the relationship between two variables according to a third one. In this case, we examined the relation between the Sepal Length and the Sepal Width of the flower, but for eachspecies
in the dataset. It is expressed with the formulax ~ y | z
.For your case, we will plot all the observations in a single standard plot. In this case, the argument
groups
will automatically color each observation according to the criteria you choose, in this case,species
again.Use the
ggplot2
package which is widely used for applications such as these.The code above provides the following graph.