in Education by
I am running the code and it works ggplot(data_df, aes(x= RR, y= PPW, col = year)) + geom_point(size = 3, alpha=0.6) Now I am trying to put the mean value of (x,y) on graph en give it another color by adding ggplot(data_df, aes(x= RR, y= PPW, col = year))) + geom_point(size = 3, alpha=0.6) + geom_point(data=data_df, aes(x=mean(RR), y=mean(PPW)) + geom_point(color="red") It works, but the color of all points is now red If I put color inside aes like these, the mean point get another color, and I see it also in legend ggplot(data_df, aes(x= RR, y= PPW, col = year))) + geom_point(size = 3, alpha=0.6) + geom_point(data=data_df, aes(x=mean(RR), y=mean(PPW), color="red")) I would like to give the color manually. Is it possible? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You're missing two key points about how ggplot manages aesthetics: Each geom_* layer will inherit the aes settings from the parent ggplot call, unless you manually override it. So in you first example, the 3rd geom_point inherits the x and y values from ggplot, not the "mean" layer above it, and thus renders a red point on top of each colored point. Values in the aes are applied to a scale, not used as is. So when you put color = 'red' in the aes in your second example, you aren't making the points red, you're saying that color should be determined by a categorical variable (which here is a length 1 vector consisting of the word 'red') based on the scale_color_*. You can either add a scale_color_manual and set 'red' = 'red', so that value renders the desired color, or move the color= outside the aes, so it is interpreted as is (and will make all points in that layer red). With those points in mind, doing what you want is as simple as moving the color outside the aes: ggplot(data_df, aes(x= RR, y= PPW, col = year))) + geom_point(size = 3, alpha=0.6) + geom_point(data=data_df, aes(x=mean(RR), y=mean(PPW)), color="red")

Related questions

0 votes
    Is it possible to change the default values of formal parameters in an R function at runtime? Let's assume, we have the function f...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to plot a geom_rect(). Why do I receive an Error in FUN(X[[i]], ...) : ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have a list of ggplots of simple ggplot line graphs based on a location. I created a list of ggplot ... (rnaturalearthdata) library(dplyr) library(ggthemes) #create line plot x...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    ________ modify a ggplot or theme object by adding on new components. (a) +.gg (b) -.gg (c) /.gg ... Data Analysis of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    Which of the following creates a new ggplot plot from a data frame? (a) qplot_ggplot (b) ggplot.data. ... Analysis of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    __________ create a complete ggplot appropriate to a particular data type. (a) autoplot (b) is.ggplot (c) ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I'm graphing data with ggplot and animating it using gganimate. I have colors as my labels and when I add a ... changing the labels from color names to the number codes. df...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    I'm graphing data with ggplot and animating it using gganimate. I have colors as my labels and when I add a ... changing the labels from color names to the number codes. df...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I've been trying to use plot_ly with transforms (ultimately to subset data from a dropdown menu) and a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Order Bars in ggplot2 bar graph (14 answers) Closed 3 years ago. I ... -interventions", "Compliance", "Timing of outcome assessments" data...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Order Bars in ggplot2 bar graph (14 answers) Closed 3 years ago. I ... -interventions", "Compliance", "Timing of outcome assessments" data...
asked May 19, 2022 in Education by JackTerrance
0 votes
    In a simple linear regression model (One independent variable), If we change the input variable by 1 unit. How ... of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    I'm trying to change the color of text lines containing "Accepted" to green and all others to red ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I am trying to display a DatePicker dialog on top of another activity and what is happening is it is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    (This is a random image of showing a Dialog found on the Internet.) I've been implementing a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
...