r - Linetype and Guide options for ggplot2 when using geom_smooth with continuous variables -
I am using ggplot2 and geom_smooth functions to build an approximate line from an LM model. I am continuously using the y and x function in my ggplot code.
I am trying to create a different line type for each line in the plot (which is -1, 0, or 1 to the variable "location"), and I would like to list each location Guide (where -1 = Place A, 0 = Location B, and 1 = Location C). A replica portion of my code is below:
# test score which is between 1 and 7 digits < -c (6, 3, 5, 6, 7, 2, 4, 6, 3, 5, 4, 3, 3, 1, 3, 3, 3, 5, 2, 3, 2, 2, 7, 3 , 7, 5, 4, 1, 3, 2, 7, 6, 6, 3, 6) # Location and LT of school location; - C (1, 0, 0, 0, 1, 1, 1, -1, -1, -1, 0, -1, 0, 1, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0) IQ and lieutenant; - c (0.7171425604, .7056850461, 1.3929736220, .0633 9 36624, -0.6872828336, -1.3665840767, 1.436856 99 44, .72975 99 487, -0.5735047485, -0.6752,912747, -0.6213572428, -0 6110533 9 24, -0.70 9 021238, .0501744806, 1.3916802944, -0.00552431 94, 1.361 9 7532 92, 1.440636 9 365, .652 9010186, .05380 9 789, 1.3821853866, 1.3870600 99 3, 0.0040551996, 0.6600558495, 1.3550162100, 1.3081187951, - 1.7541949601, 1.3768167017, -0.6232446826, -1.2793074919, 0.0560708725, -0.5993356051, -085857733192, -0.6005459705, -0.6659873442) DF & Lt ; - data.fr (score, location, intelligence) p1 & lt; - ggplot (data = df, aes (y = score, x = IQ, size = factor (location)) + geom_smooth (method = "lm", to = f) + scale_i_continus ("test score", limit = c ( 1,7)) + scale_x_continuous ("IQ level", border = c (-2.45, 1.45)) + theme_bw () + theme (axis.Text.x = Element_text (size = relay (1.2), color = 'black' ), Axis. Title.x = element_text (size = rel (1.3)), axis.title.y = element_text (size = rel (1.3)), axis .text.y = element_text (size = rel (1.2), color = 'Black'), panel.grid.minor = element_blank (), panel.grid.major.x = element_blank (), panel.grid.major.y = Element_blank (), axis.ticks.y = element_blank (), Panel.border = element_blank (), plot.title = element_text (size = rel (1.4)) (P1)
Whenever I try to add linux or manual linux, I keep errors about how linety can be used with continuous variables (only discrete) Can not be mapped. Is there any way around this or should I use a different function? Maybe prepare the labels for location values (School 1, School 2, and School 3?)? Or should I use some options for lintip? I'm not getting a solution online or in the book of Wiki Thanks!
You are receiving this error message because location
is constantly changing (numeric The variable is considered to be continuous in the GG Plot) and only the discrete variable can be used for linetype =
. To change the label in the use of the factor legend, use cale_linetype ()
to provide linetype =
to convert space
label =
. Ggplot (data = df, aes (y = score = x = IQ, linetype = factor (location))) + geom_smooth (method = "lm", se = F) + scale_y_continuous ( "Test score", limit = C (1,7)) + scale_x_continuous ("IQ level", boundary = C (-2.45, 1.45)) + scale_linetype (label = c ("location a", "position b", " Location c "))
Comments
Post a Comment