legend

How to show abline of geom_abline in legend

余生颓废 提交于 2019-11-29 16:14:07
in the following sample data , how can i display the abline ( i e the red color line) in legend with y. my code and data: x<-c(1990,1991,1992,1993,1994,1995) y<-c(400,500,465,450,550,555) df<-data.frame(x,y) df plot1<- ggplot(df, aes(x)) + geom_line(size=0.5,lty="dashed", aes(y=y),color="Blue") + geom_abline(aes(slope=-0.62,intercept=1670,colour="break"),size=0.9)+ geom_point(aes(y=y,shape="y"),size=4, color="Gray24",fill="Green") plot1 . what i got is the below image. i need the red line to be displayed in legend tkmckenzie You can use the show_guide=TRUE argument: plot1<- ggplot(df, aes(x))

Custom legend of several lines with two markers for the same text

做~自己de王妃 提交于 2019-11-29 15:32:23
I would like perform the type of legend shown in the figure . That figure I did with some tricks just to represent what I really want so it does not show well the color of the pink markers in the legend. In the figure the circles represent the same parameter but for two different models; the same is true for the triangular and square markers. I want to place the two circular markers referring to the same parameter in the first line of the legend, and analogously for the two other markers on the lines below this one. Thank you. Code: import matplotlib.pyplot as plt q1 = [100.0, 60.0, 200.0, 300

Make squared in legend instead of lines Matlab

我们两清 提交于 2019-11-29 14:51:04
I have the following code, which plots a 'map' using imagesc, and provides a legend, see output attached. I am trying to replace the lines in the legend with solid squares. My attamps to far leave the lines and ad hollow squares (including a random square in the top left corner of the figure) figure(6) imagesc(lut) title('Ditribution of Land use Types') ylabel('Longitude') xlabel('Latitude') caxis([0, 7]) myColorMap = jet(6); imagesc(lut, 'AlphaData', ~isnan(lut)) colormap(myColorMap); L = line(ones(6), ones(6)); set(L, {'Color'}, num2cell(myColorMap, 2)) legend(L, {'Forest','Shrubland',

How to add legend for vertical lines in ggplot?

落爺英雄遲暮 提交于 2019-11-29 14:25:41
I am trying to show a line graph with some vertical lines as indicators of particular time points and have a legend labeling those time points. Based on the example in section 6.4.4 of the book ggplot2, I've tried the following huron<-data.frame(year=1875:1972,level=LakeHuron) vertDf<-data.frame(years=c(1900,1925,1950),labels=c("A","B","C")) pltWithLines<-ggplot(huron, aes (x=year,y=level)) + geom_line() + geom_vline(aes(xintercept=years,color=labels),data=vertDf) + scale_color_manual("Sample Year", values=c("A"="blue","B"="red","C"="green")) This produces a graph with the vertical lines

matplotlib: put legend symbols on the right of the labels

自古美人都是妖i 提交于 2019-11-29 14:08:11
问题 It's a simple thing but I've searched for quite a while without success: I want to customise a figure legend by reversing the horizontal order of the symbols and labels. In Gnuplot, this is simply achieved by set key reverse . Example: change x data1 to data1 x . In matplotlib, there seems to be no user-friendly solution. Thus, I thought about changing a kind of handle anchor or just shifting the handle's position, but couldn't find any point to start with. 回答1: The requested feature is

Matplotlib : making a colored markers legend from scratch

回眸只為那壹抹淺笑 提交于 2019-11-29 12:45:02
问题 In Matplotlib, i'm trying to make a legend with colored "markers" like this one : this one has been made using the scatter function, but is not adapted to my plot. I'd like to produce a legend "from scratch", without associated data. The color is important, and therefore should be an attribute of each marker. I've tried import matplotlib.markers as mmark list_mak = [mmark.MarkerStyle('.'),mmark.MarkerStyle(','),mmark.MarkerStyle('o')] list_lab = ['Marker 1','Marker 2','Marker 3'] plt.legend

How do I change the legend position in a NVD3 chart?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 11:40:11
问题 Does anyone know how to reposition the legend in a NVD3 chart relative to the graph itself? It is on top by default, and I would like it to go on the side (better use of space within my app) An example of what I would like to do: 回答1: There is AFAIK no option to do this, but you can select the g element that contains the legend manually and move it, e.g. d3.select(".nv-legendWrap") .attr("transform", "translate(100,100)"); 回答2: As of this writing (2 jul 2015) nvd3 supports putting the legend

Chart.js legend took up too much spaces

我怕爱的太早我们不能终老 提交于 2019-11-29 11:15:25
I was having some problem with chart.js legend. The legend with long text took up too much spaces which resulting in the reduce in the size of my pie chart: Another example is this: If I got more legend, the doughnut chart will eventually becomes smaller and smaller. I tried to set maxWidth but to no avail. var options = { layout: { padding: { top: 5 } }, responsive: true, maintainAspectRatio: false, legend: { display: true, position: 'right', maxWidth: 100, onClick: null }, animation: { animateScale: true, animateRotate: true }, }; Any ideas? Thanks in advanced! I tried to follow this

Single legend when using group, linetype and colour in ggplot2?

≯℡__Kan透↙ 提交于 2019-11-29 10:11:18
I am creating a very simple plot that groups data and uses the grouping variable to determine linestyle and colour. I then override those using 'scale_linetype_manaul' and 'scale_colour_manual'. So far so good, but when I try to modify legend labels or its title, the legend splits into two parts: one for linetype and one for colour. I just want one legend, but with the custom labels and title. Following this question , I made sure to name both scale objects the same, but that doesn't appear to help. Minimal example: X <- data.frame(TPP=factor(c(1,5,10,1,5,10,1,5,10)), value=c(-0.035819, 0

ggplot legend showing transparency and fill color

假装没事ソ 提交于 2019-11-29 09:23:47
I'm plotting two semi-transparent ribbons together. Using the code below, without the scale_fill_manual portion, I get basically what I want, with a legend called "red" , and labels blue and red . Adding the scale_fill_manual portion allows me to name the legend and its entries what I want, but i lose the transparency of the colored rectangles in the legend. x=1:10 y1=1:10 y2=2:11 y3=10:1 y4=9:0 dt=data.frame(x,y1,y2,y3,y4) library(ggplot2) ggplot(dt)+ geom_ribbon(aes(x=x,ymin=y1,ymax=y2,fill='red'), alpha=0.4,)+ geom_ribbon(aes(x=x,ymin=y3,ymax=y4,fill='blue'), alpha=0.5)+ scale_fill_manual