legend

R - How to add legend title to levelplot saved to a variable?

回眸只為那壹抹淺笑 提交于 2019-12-07 12:16:39
问题 I would like to add the title for a legend in a levelplot graph saved to a variable. For example, this code works: library(lattice) library(grid) x = 1:10 y = rep(x,rep(10,10)) x = rep(x,rep(10)) z = x+y levelplot(z~x*y, colorkey=list(labels=list(cex=1,font=2,col="brown"),height=1,width=1.4),main=list('b',side=1,line=0.5)) trellis.focus("legend", side="right", clipp.off=TRUE, highlight=FALSE) grid.text(expression(m^3/m^3), 0.2, 0, hjust=0.5, vjust=1) trellis.unfocus() But this code, where the

Graduated size symbols in legends

佐手、 提交于 2019-12-07 12:12:56
问题 I have plotted a bubble chart with the circles' sizes corresponding to a list of values using matplotlib. However, I'm having trouble creating a legend for the plot that has variable size symbols that corresponds to the listed size. Such as the one in the link above. Is there a way to create this legend in matplotlib without manually drawing circles and text on the plot? Thanks in advance for your time and thoughts! Cindy 回答1: Yes, you can be specific about which data you make a legend for

ggplot2 completely custom legend?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 12:08:29
问题 Is there any way that I can create a completely custom legend that won't care about the aesthetics or anything else in my plot? I would like if possible to design everything from scratch. How many groups of legends I will have, what will be the title, shape, color, size, linetype, fill, label, order etc for each legend. I have already spent almost two working days try to figure out how to create the legends to look the way I want them to look (The plot itself didn't take more than a few

Matplotlib legend help

好久不见. 提交于 2019-12-07 11:49:01
问题 I am writing a script that plot's several points. I am also trying to create a legend from these points. To sum up my script, I am plotting several 'types' of points (call them 'a', 'b', 'c'). These points have different colors and shapes: 'a'-'go' 'b'-'rh' 'c'-'k^'. This is a shortened version of the relevant parts of my script: lbl = #the type of point x,y is (a,b,c) for x,y in coords: if lbl in LABELS: plot(x, y, color) else: LABELS.add(lbl) plot(x, y, color, label=lbl) legend() What I am

Two line styles in legend

◇◆丶佛笑我妖孽 提交于 2019-12-07 11:38:22
问题 I have a plot with two line styles (solid and dashed). I would like them to be used for the same legend entry. The code below produces the typical legend, with two entries. import matplotlib.pyplot as plt import numpy as np xy = np.linspace(0,10,10) plt.figure() plt.plot(xy,xy, c='k', label='solid') plt.plot(xy,xy+1, c='k', ls='dashed', label='dashed') plt.plot(xy,xy-1, c='k', ls='dashed') plt.legend() plt.show() What I would like is something similar to this: I have tried playing with proxy

scale_fill_manual based on another factor in ggplot2

爷,独闯天下 提交于 2019-12-07 10:43:40
问题 I am trying to color-code my legend based on a broader categorization of the factor used to "fill" my geom_bar in ggplot2. My plot looks like this: which I got using this R code: ggplot(df, aes(year, TOTALshark, fill=fishery)) + geom_bar(width=.5,stat="identity", position="dodge")+ facet_wrap(~div) Here is a dput sample of my dataset: > dput(smpl) df <- structure(list(X1 = structure(c(6L, 11L, 22L, 27L, 10L, 10L, 6L, 11L, 6L, 10L, 8L, 6L, 6L, 4L, 22L, 18L, 10L, 10L, 11L, 6L ), .Label = c(

How to manipulate legend in Incanter chart

♀尐吖头ヾ 提交于 2019-12-07 10:31:28
问题 I'm trying to include a legend in an Incanter chart, but I'm having some troubles getting what I want: I want to be able to instantiate a chart with no data first (using [] [] as my x y arguments), then add the data points in a separate step. However the only way to add a legend is to specify :legend true after the initial x y points are given in the constructor. Cannot specify :legend true without x y arguments, and I have not found any add-legend function. The legend option captures the

how to remove line from fill scale legend using geom_vline and geom_histogram r ggplot2

ぃ、小莉子 提交于 2019-12-07 07:11:32
问题 Basics: Using R statistical software, ggplot2, geom_vline, and geom_histogram to visualize some data. The issue is with the legend keys. I'm trying to plot a pair of histograms from some stochastic simulations, and on top of that plot a couple of lines representing the result of a deterministic simulation. I've got the data plotted, but the legend keys for the histograms have an unnecessary black line through the middle of them. Can you help me remove those black lines? Some sample code

Add legend to scatter plot

╄→尐↘猪︶ㄣ 提交于 2019-12-07 06:35:08
问题 This question has been asked on SO, but I want to find a clearer solution. Given X is 100x2 data, and labels is the label vector ( from 1 to 9) I plot the scatter plot as following: pl.scatter(X[:,0], X[:,1], c = labels) pl.show() How to add legend to explain the colors in just one line of code? Other solutions plot each label separately: a = pl.scatter(X1[:,0], X1[:,1], color = "red") b = pl.scatter(X2[:,0], X2[:,1], color = "green") c = pl.scatter(X3[:,0], X3[:,1], color = "blue") pl.legend

Matlab: Combine the legends of shaded error and solid line mean

人走茶凉 提交于 2019-12-07 05:55:48
问题 I am using this FEX entry to plot the horizontal shaded error bars for a variable plotted on the X-axis. This variable is plotted in different regions/zones and, therefore, there are 3 shaded error bars for 3 zones. I would like to combine the legends of the error bars (shaded region) as well as the mean (solid line) of any zone into a single legend represented by a solid line (or solid line inside a patch) of the same color as the zone. THE WAY MY CODE WORKS FOR PLOTTING: A synthetic example