legend-properties

ggplot2 draws two legends

混江龙づ霸主 提交于 2019-11-28 08:48:39
I have almost complete the following graph, but there is one problem with it. The legend in the graph is drawn twice. Here is the data: structure(list(Period = c("January 1997 - August 2003", "September 2003 - Jun 2005", "Jul 2005 - Dec 2009", "January 1997 - August 2003", "September 2003 - Jun 2005", "Jul 2005 - Dec 2009"), Time.Period = structure(c(1L, 3L, 2L, 1L, 3L, 2L), .Label = c("Jan 1997 - Aug 2003", "Jul 2005 - Dec 2009", "Sep 2003 - Jun 2005"), class = "factor"), Variable = structure(c(2L, 2L, 2L, 1L, 1L, 1L), .Label = c("Significant", "Zscore"), class = "factor"), Score = c(8.798129

Legend does not show line type in ggplot2 density plot

回眸只為那壹抹淺笑 提交于 2019-11-28 08:23:00
问题 I created a density plot with ggplot from a dataframe with 3 variables. One density line is dotted, but the legend shows a solid line for this line. The data looks like this: > head(df) R1 R2 R3 1 0.085383867 0.04366546 0.055320885 2 0.059148932 0.03477045 0.040804048 3 -0.181279986 -0.10189900 -0.097218145 4 0.002307494 -0.01137235 -0.003585813 5 -0.047816198 -0.04932982 -0.009389939 6 0.030535090 0.02544292 0.017650949 The code for the plot is: ggplot(data=df)+ stat_density(aes(x=R1, colour

How to move or position a legend in ggplot2

别来无恙 提交于 2019-11-28 07:07:36
I'm trying to create a ggplot2 plot with the legend beneath the plot. The ggplot2 book says on p 112 "The position and justification of legends are controlled by the theme setting legend.position, and the value can be right, left, top, bottom, none (no legend), or a numeric position". The following code works (since "right" it is the default), and it also works with "none" as the legend position, but "left", "top", "bottom", all fail with "Error in grid.Call.graphics("L_setviewport", pvp, TRUE) : Non-finite location and/or size for viewport" library(ggplot2) (myDat <- data.frame(cbind(VarX=10

How to change angle of line in customized legend in ggplot2

对着背影说爱祢 提交于 2019-11-27 22:30:54
I'm trying to add a customized legend to my ggplot but the legend boxes have lines at an angle. I want to change that angle to 0 degrees. Is there any way to do that? Following is the code for an example plot. ggplot()+geom_abline(aes(color="black",,slope=1,intercept = 0))+ geom_abline(aes(color="red",slope=0.5,intercept = 0))+ scale_color_manual(values=c("black"="black","red"="red")) We can see that the lines in the legend boxes are slightly inclined and I want to make them horizontal. You can change how the lines are drawn in the key: I changed y0 and y1 of the segmentsGrob, so that they are

Different legend-keys inside same legend in ggplot2

懵懂的女人 提交于 2019-11-27 14:40:53
Let's say I don't need a 'proper' variable mapping but still would like to have legend keys to help the chart understanding. My actual data are similar to the following df df <- data.frame(id = 1:10, line = rnorm(10), points = rnorm(10)) library(ggplot2) ggplot(df) + geom_line(aes(id, line, colour = "line")) + geom_point(aes(id, points, colour = "points")) Basically, I would like the legend key relative to points to be.. just a point, without the line in the middle. I got close to that with this: library(reshape2) df <- melt(df, id.vars="id") ggplot() + geom_point(aes(id, value, shape =

Is it possible to add a string as a legend item in matplotlib

我们两清 提交于 2019-11-27 08:01:14
I am producing some plots in matplotlib and would like to add explanatory text for some of the data. I want to have a string inside my legend as a separate legend item above the '0-10' item. Does anyone know if there is a possible way to do this? This is the code for my legend: ax.legend(['0-10','10-100','100-500','500+'],loc='best') Sure. ax.legend() has a two argument form that accepts a list of objects (handles) and a list of strings (labels). Use a dummy object (aka a "proxy artist" ) for your extra string. I picked a matplotlib.patches.Rectangle with no fill and 0 linewdith below, but you

How to add data table with legend keys to a MS Chart in C#?

纵饮孤独 提交于 2019-11-27 05:41:38
There are 2 lists called listversion & MIN_list . Using values of these list I have created a line chart. Everything is work fine. But I am wondering whether it is possible to add a data table with legend keys in to the chart like MS Excel. chart.Series.Clear(); chart.ChartAreas[0].AxisX.Title = "Version"; chart.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Arial", 12, FontStyle.Regular); chart.ChartAreas[0].AxisY.Title = "Time"; chart.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Arial", 12, FontStyle.Regular); Series MIN = chart.Series.Add("Minimum"); MIN.Points

How to change angle of line in customized legend in ggplot2

混江龙づ霸主 提交于 2019-11-27 04:35:15
问题 I'm trying to add a customized legend to my ggplot but the legend boxes have lines at an angle. I want to change that angle to 0 degrees. Is there any way to do that? Following is the code for an example plot. ggplot()+geom_abline(aes(color="black",,slope=1,intercept = 0))+ geom_abline(aes(color="red",slope=0.5,intercept = 0))+ scale_color_manual(values=c("black"="black","red"="red")) We can see that the lines in the legend boxes are slightly inclined and I want to make them horizontal. 回答1:

ggplot2 draws two legends

守給你的承諾、 提交于 2019-11-27 02:26:40
问题 I have almost complete the following graph, but there is one problem with it. The legend in the graph is drawn twice. Here is the data: structure(list(Period = c("January 1997 - August 2003", "September 2003 - Jun 2005", "Jul 2005 - Dec 2009", "January 1997 - August 2003", "September 2003 - Jun 2005", "Jul 2005 - Dec 2009"), Time.Period = structure(c(1L, 3L, 2L, 1L, 3L, 2L), .Label = c("Jan 1997 - Aug 2003", "Jul 2005 - Dec 2009", "Sep 2003 - Jun 2005"), class = "factor"), Variable =

How to move or position a legend in ggplot2

a 夏天 提交于 2019-11-27 01:43:33
问题 I'm trying to create a ggplot2 plot with the legend beneath the plot. The ggplot2 book says on p 112 "The position and justification of legends are controlled by the theme setting legend.position, and the value can be right, left, top, bottom, none (no legend), or a numeric position". The following code works (since "right" it is the default), and it also works with "none" as the legend position, but "left", "top", "bottom", all fail with "Error in grid.Call.graphics("L_setviewport", pvp,