Tuesday 15 March 2011

plot - ggplot2 - trouble with legend when using geom_point() in (R) -


I try to create a ggplot with two geom_line () S and two geom_point () s, all come from the same dataset (I currently get a data.table ). The data looks like this:

  & gt; Head (Data) Month High_Low_q1: 2009-03-01 0.048 9 4481 0.1462436 2: 2009-04-01 0.04910757 0.1452902 3: 2009-06-01 0.04871459 0.1471519 4: 2009-07-01 0.04938127 0.1489580 5: 2009-08 -01 0.04899900 0.1481020 6: 2009-09-01 0.04888317 0.1479808  

Plot me against high_q and low_q month , both as geom_line () s and geom_point () s. So far, I have found:

Enter image details here

which is generated by using:

  requires the plot ('ggplot2'); - geom_line (data = data, aes (x = month, y = high_ q, (Data = data, AES X = month, y = low_q), size = 0.15, color = 'gray 40') + geom_point (data = data, color = 'headquarters'), shape = 0, size = 1.2) + GOM_LINE (data = AES (x = months, y = less_a, color = 'lq'), shape = 2, size = 1.2) + Scale_color_manual (values ​​= c ("skyblue4", "skyblue4")) + theme_bw () + theme Panel.grid.minor.x = element_blank (), panel.grid.major.x = element_blank (), panel.grid.major.y = element_line (color = '#CCCCCC'), panel.grid.minor.y = Element_line (color = '#CCCCCC'), axis.title.x = element_blank (), a Xis.title.y = Element_blank (), axis.text = elem linand.KIICE = unit (0.3, "cm") + scale_y_continuous (breaks = seq (0, 1, 0.02), limitations = c (0.04, 0.16) )  

For my purposes, everything is recovering, how do I want to do it except for a small problem: legend entries 'headquarters' and For the 'LQ', the size of the triangle and the overlapping of each other over each other is as follows (as can be seen in the above plot). I can not understand why this is happening, but I want to show the appropriate size (class and triangle respectively) for the 'HQ' and 'LQ' I would like a legend.

The data to reproduce it is as follows:

  is required ('data.table') # Not sure it is necessary , But in case & gt; Dput structure (list (month = structure (C (15584, 15614, 15645, 15675, 14 9 75, 15006, 15034, 15065, 1509, 15156, 15187, 15218, 15248, 15279, 15340, 15400, 15492, 15553, 15126, 15,371, 15522, 15,309, 15461, 15431), class = "date"), high_q = c (.0543422228029794, .0538360449888788, .0542576885322506, .0563374158664627, .051832022940258, .0511098243497093, .0516824037401732,. 0508625794149931, 0.0508129898329969, 0.0522992472796989, 0.0534593224542862, 0.053658852482904, 0.0527596522451362, 0.0536379383601105, 0.0537250634604839, 0.053270060949945, .0551497117304649, .05453991405068, 0.0514309991121669, 0.0528033236299854, 0.0556533741364405, 0.0575938660077188, 0.0536383751376219, .0540292765156109) , Low_q = c (0.150651382807563, .151678928161841, .152412405006079, .15434629712537, .148160747764117, .145711811622833, .146989273508668, .145807363651857, .146620317131406, .152241594600521, .154136431058451, .151915467273669, 0.1514212 12763034, 0.152599450134152, 0.149039642113193, 0.14629263019443, 0.149301086354786, 0.150844206416902, 0.148202127121, 0.152041900070419, 0.152751500401794, 0.147225953877478, 0.146177782497413) .. Name = C ("month", "high_k", "low_key"), line.Name = C (NA, -24L), square = C ("data valid", "data.frame"))  

I understand that ggplot2 is in long I like the data in the format, so I always melts my data first:

  Library (recieve 2) df & lt; You can then plot it using:  

It gives you the basis after that, that is, different shapes in mythology. Then you can add additional topics as you want.


No comments:

Post a Comment