I have a dataframe of 407 observations of 14 variables. Using ggplot2 or other graphics I can easily create a scatterplot of one of the variables against another to allow me to observe patterns.
I would like to be able to highlight some of the points in the scatterplot that are of interest because of the pattern they make within the plot and then call the associated information from the dataframe. Is there a package that can do this?
There are no other variables within the dataframe that would allow me to distinguish the group of interesting points in the plot. This would make the problem much simpler.
I am aware that this may be a bigger question than I think it is and I am grateful for any pointers in the right direction!
Many thanks!
Nicki
Here are two options:
identify()in base R and theiplotspackage.First, you can use
identify()to identify and label points on aplot()as you click on them:Now if we click on the plot, it will search for the nearest data point, return its index, and, by default (unless we add the plot = FALSE argument), label that point with its index.
We stop the identification process by clicking the secondary mouse button and selecting ‘Stop’ from the menu, or by selecting ‘Stop’ on the graphics window. Since we’ve stored the output in a variable named interesting, we can easily examine the points:
The
iplotspackage, which does really nice interactive linked plots, provides a fancier solution:Using iplots, you can highlight data on one plot and have them change colors on all plots. Here I have selected the red points in the lower plot, changing their color on both plots.
After highlighting a subset of data, we can determine the currently selected points with
iset.selected(), as in:Since you have 14 variables, mutiple
iplot()scatterplots might be more effective than usingidentify().