IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 103 forks source link

Global data frame being overridden when a second geom with a different data frame is added #4450

Open bethanclarke opened 6 years ago

bethanclarke commented 6 years ago

Suppose we have created a scatter plot and now we want to circle some specific points on the plot. Then, we would use a second layer called geom_encircle to do so. In order for the geom encircle to circle specific points, we need to filter the data frame used to create the scatter plot, save it as a new data frame and then map this data frame to geom encircle.

Example Create a scatter plot ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point() Then to circle specific points, we map our filtered data to the data parameter in geom_encircle ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point() + geom_encircle(data = mtcarsfiltered)

However, when we map a different data frame in the second geom, the global data frame is overridden i.e. the data frame used in the first layer is replaced. So it updates the data frame everywhere, rather than in just the second layer (in this case geom_encircle). So the code looks like this rather than the example above:

ggplot(data = mtcarsfiltered, aes(x = wt, y = mpg)) + geom_point() + geom_encircle(data = mtcarsfiltered)

To over come this problem we need to check "Apply on all layers" when creating the scatter plot with geom_point

dannyparsons commented 6 years ago

This looks like it's almost working because the second data frame is getting added into the second layer. So we just need it to not change the global data frame when apply on all layers is unchecked.