r - More than six shapes in ggplot -


I want to draw a diagram with different shapes with more than six data sets, using discrete colors. Problems 1) A different legend line is produced for color and shape, but should be only a legend with line color and shape, 2) When the line colors correct the title for the legend, the colors disappear. (IP == 0) {df & lt; for -data.frame (t = t, y)

  t = seq (0,360,20) (seq (0,10) in IP = sin (t * pi / 180) + ip / 2, sn = ip + 100)} and {tdf & lt; -data.frame (t = t, y = sin (t * pi / 180) + ip / 2, sn = ip + 100) df & lt; -rbind (df, tdf)}} head (df) # a plot # error: a continuous variable to be called GP & lt; - ggplot (df, aes (x = t, y) can not be mapped to size = y, group = sn, color = sn, size = sn)) GP & LT ; - GP + Labs (title = "size more than demo 6", x = "theat (dj)", y = "magitium") GP & Lt; - gp + geom_line () + geom_point () print (gp) # no plot # error: a continuous variable can not be mapped as size (integer not liked) GP & lt; - ggplot (df, aes (x = t, y = y, group = sn, color = sn, size = as.integer (sn))) GP & LT; - GP + Labs (title = "size more than demo 6", X = "Thatt (degree)", Y = "magnitude") GP & lt; - GP + geom_line () + geom_point () print (GP) warns about # 6 sizes, and shows only 6 sizes, continuous SO color GP & lt; - ggplot (df, aes x = t, y = y, group = sn, color = sn, size = as. Fact (sn)) GP & LT; - GP + Labs (title = "Only shows six sizes, and two legends, need discrete colors", X = "theat (degree)", y = "magnetity") GP & lt; - GP + geom_line () + geom_point () Print (GP) # This is desired, but right Legend title and alliance legends GP & lt; - ggplot (df, aes (x = t, y = y, group = sn, color = as.factor (sn), size = afactor (sn %% 6)) gp & Lt; - GP + Labs (title = "Need to combine legends and perfect mythology", X = "theatrical", y = "magnitude") GP-> GP + GOP_LINE () + GOM_point () Print (GP) # Right Legend Title, But Now Line Color GP & Lt; - GG Plot (DF, AES (X = T, Y = Y, Group = SN, Color = AFactor (S) N.), Size = AFactor GP + Lab (title = "Color disappeared, but title of Legend changed", X = "Theat (degree)", y = "Vantage") GP & lt; GP + GOM_Line () + Geom_point () gp & lt; -gp + scale_color_manual ("sn", value = as.factor (df $ sn)) Print (gp) # geom_line / geom_point Add color and size to command, GP & Lt; - ggplot (df, ae (x = t, y = y, group = SE)) GP & LT; - GP + Labs (title = "It is close, but myths are wrong", X = "theat ( Degree) ", y =" journal pedigree ") P & lt; - GP + Jiom_lain (AES (color = A.afactor (DF $ Saif)) GP & lt; - GP + GOM_Point (Color = AF Actor (DF Dollar SE), Size = AFactor (Df $ sn %% 6)) GP & lt; - GP + scale_color_manual ("SN", value = as .factor (df $ sn)) Print (GP)    

Firstly, changing sn to one factor will be easy.

  df $   

Then, you need to use scale_shape_manual to specify your size to use is.

  GP and LT; - GGPlot (DF, AES (X = T, Y = y, Group = SN, Color = SN, Size = SN)) + Scal_Shap_manual (Value = 1: Envelopes (DF Dollar SEP) ) + Labs (title = "demo over size 6", x = "theat (degree)", y = "vastness") + geom_line () + geom_point (size = 3) gp   < P> It should be what you need to use  scale_shape_manual  because even  sn  as a factor,  ggplot  Automatically only 6 different symbols After that, you will need to manually specify them after that. You can change your symbols in many ways. See how to find more information on these pages: 

Enter image details here

Comments

Popular posts from this blog

java - Joda Time Interval Not returning what I expect -

Member with no value in F# -

javascript - Render HTML after each iteration in loop -