legend

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,

creating a matplotlib scatter legend size related

别说谁变了你拦得住时间么 提交于 2019-11-27 01:39:23
问题 I am looking for a way to include a (matplotlib) legend that describe the size of points in a scatter plot, as this could be related to another variable, like in this basic example: import numpy as np import matplotlib.pyplot as plt N = 50 x = np.random.rand(N) y = np.random.rand(N) a2 = 400*np.random.rand(N) plt.scatter(x, y, s=a2, alpha=0.5) plt.show() (inspired from: http://matplotlib.org/examples/shapes_and_collections/scatter_demo.html) so in the legend there would be ideally few spots

ggplot legend issue w/ geom_point and geom_text

[亡魂溺海] 提交于 2019-11-27 01:38:03
问题 I am trying to use geom_point to illustrate the count of my data. I would also like to annotate a few of the points in my graph with geom_text . When I add the call to geom_text , it appears that it is plotting something underneath the points in the legend. I've tried reversing the order of the layers to no avail. I can't wrap my head around why it is doing this. Has anyone seen this before? set.seed(42) df <- data.frame(x = 1:10 , y = 1:10 , label = sample(LETTERS,10, replace = TRUE) , count

Matplotlib scatter plot with legend

痞子三分冷 提交于 2019-11-27 01:27:15
I want to create a Matplotlib scatter plot, with a legend showing the colour for each class. For example, I have a list of x and y values, and a list of classes values. Each element in the x , y and classes lists corresponds to one point in the plot. I want each class to have its own colour, which I have already coded, but then I want the classes to be displayed in a legend. What paramaters do I pass to the legend() function to achieve this? Here is my code so far: x = [1, 3, 4, 6, 7, 9] y = [0, 0, 5, 8, 8, 8] classes = ['A', 'A', 'B', 'C', 'C', 'C'] colours = ['r', 'r', 'b', 'g', 'g', 'g']

ggplot2: Different legend symbols for points and lines

断了今生、忘了曾经 提交于 2019-11-27 01:08:42
问题 already searched all related threads about this but could not find a solution. Here is my code and the attached plot result: g <-ggplot(NDVI2, aes(LAI2, NDVI, colour = Legend)) + theme_bw (base_family = "Times") + scale_colour_manual (values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black")) + geom_point (size = 3) + geom_smooth (aes(group = 1, colour = "Trendline"), method = "loess", size = 1, linetype = 5, se = FALSE) + geom_smooth (aes(group = 1, colour =

Common legend for multiple plots in R

假装没事ソ 提交于 2019-11-27 00:40:28
I am using R and Latex together to draw some plots and am trying to make a common legend for all of them. I have six separate plots on the same page. I made each plot separately in R and then displayed them on the same page using \includegraphics in Latex. Each graph has the same legend information, so rather than having a legend in each plot I would like to have one horizontal legend on display at the bottom of page. Unfortunately, I can't figure out how to make a legend without a plot. Once I have a separate image for the legend, I will know how to include it at the bottom of the page using

R legend placement in a plot

醉酒当歌 提交于 2019-11-27 00:18:12
问题 I have a plot that has data that runs into the area I'd like to use for a legend. Is there a way to have the plot automatically put in something like a header space above the highest data points to fit the legend into? I can get it to work if I manually enter the ylim() arguments to expand the size and then give the exact coordinates of where I want the legend located, but I'd prefer to have a more flexible means of doing this as it's a front end for a data base query and the data levels

How to set font size of Matplotlib axis Legend?

自闭症网瘾萝莉.ら 提交于 2019-11-27 00:16:47
问题 I have a code like this: import matplotlib.pyplot as plt from matplotlib.pyplot import * from matplotlib.font_manager import FontProperties fontP = FontProperties() fontP.set_size('xx-small') fig=plt.figure() ax1=fig.add_subplot(111) plot([1,2,3], label="test1") ax1.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1, 1), prop = fontP,fancybox=True,shadow=False,title='LEGEND') plt.show() It can be seen in the plot that the setting in Fontsize does not affect the Legend Title font size. How to set

Why doesn't the color of the points in a scatter plot match the color of the points in the corresponding legend?

£可爱£侵袭症+ 提交于 2019-11-26 23:41:46
问题 I have a sample scatterplot via matplotlib via the code below. import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 100, 501) y = np.sin(x) label = 'xy data sample' plt.scatter(x, y, cmap='plasma', c=x, label=label) legend_dict = dict(ncol=1, loc='best', scatterpoints=4, fancybox=True, shadow=True) plt.legend(**legend_dict) plt.show() Running the code above produces the plot below. The colormap was successfully plotted, but the legend shows points that are all blue rather

Default CSS values for a fieldset <legend>

人盡茶涼 提交于 2019-11-26 23:14:38
问题 I'm trying to use a <legend> as a title inside a <fieldset> . In browsers other than IE, the <legend> is positioned on the top border of the <fieldset> , with the text perfectly centered on the line. I'm trying to reset it's position so that it sits just like any other element. i.e. an <h3> . Here's the CSS I have so far. fieldset legend { margin: 0; padding: 0; position: static; border: 0; top: auto; left: auto; float: none; display: block; font-size: 14px; line-height: 18px; } But the