legend

ggplot2: Divide Legend into Two Columns, Each with Its Own Title

爷,独闯天下 提交于 2019-11-27 03:58:11
问题 I have these factors require(ggplot2) names(table(diamonds$cut)) # [1] "Fair" "Good" "Very Good" "Premium" "Ideal" which I want to visually divide into two groups in the legend (indicating also the group name): "First group" -> "Fair", "Good" and "Second group" -> "Very Good", "Premium", "Ideal" Starting with this plot ggplot(diamonds, aes(color, fill=cut)) + geom_bar() + guides(fill=guide_legend(ncol=2)) + theme(legend.position="bottom") I want to get (note that "Very Good" slipped in the

Custom legend with imported images

与世无争的帅哥 提交于 2019-11-27 03:40:53
问题 I'm currently creating plots in ggplot2 by importing custom images and using them as geom_points, similar to this post, except I am looping through different images for unique levels of a factor. Is there an easy way to add these images to the legend? I've seen multiple posts on custom legends in ggplot2, but nothing that deals with imported images. 回答1: I'm not sure how you will go about generating your plot, but this shows one method to replace a legend key with an image. It uses grid

How to add a legend to matplotlib pie chart?

拜拜、爱过 提交于 2019-11-27 03:27:45
问题 Using this example http://matplotlib.org/examples/pie_and_polar_charts/pie_demo_features.html how could I add a legend to this pie chart? My problem is that I have One big slice 88.4%, the second largest slice is 10.6%, and the other slices are 0.7 and 0.3%. The labels around the pie don't appear (except for the biggest slice) and neither the percentage values for the smaller slices. So I guess I can add a legend showing the names and the values. But I haven't found out how... # -*- coding:

Using expression(paste( to insert math notation into a legend

我怕爱的太早我们不能终老 提交于 2019-11-27 03:21:36
问题 I wish to substitute the following (yes, I've written it here in TeX format, just to be clear) $P_{M1}(\tilde{z}>z) - P_{M0}(\tilde{z}>z)$ for the green line's legend entry (cptsdtbehavioralm), and $P_{M2}(\tilde{z}>z) - P_{M0}(\tilde{z}>z)$ for the blue line's legend entry (fullbehavioralmodel). Here is the code with which I generated the plot (I am omitting the 10,000-observation dataset and the transforms to generate the functions Fm0, Fm1 and Fm2): bmp("bias_plot_v4.bmp", width=540,

creating over 20 unique legend colors using matplotlib

ε祈祈猫儿з 提交于 2019-11-27 02:46:13
I am plotting 20 different lines on a single plot using matplotlib. I use a for loop for plotting and label every line with its key and then use the legend function for key in dict.keys(): plot(x,dict[key], label = key) graph.legend() But using this way, the graph repeats a lot of colors in the legend. Is there any way to ensure a unique color is assigned to each line using matplotlib and over 20 lines? thanks Yann The answer to your question is related to two other SO questions. The answer to How to pick a new color for each plotted line within a figure in matplotlib? explains how to define

ggplot2 add a legend for several stat_functions

送分小仙女□ 提交于 2019-11-27 02:42:25
问题 I see a lot of questions regarding how to customize legends, but I can't even get a legend to customize. I would like to have a legend explaining that the black line is quadratic and that the green line is cubic. library(ggplot2) myfun1 <- function(x) x^2 myfun2 <- function(x) x^3 myplot <- ggplot(data = data.frame(x = 1:5, y= 1:5), aes(x=x, y=y)) + stat_function(fun = myfun1, color="green") + stat_function(fun = myfun2, color="black") 回答1: Try this: ggplot(NULL, aes(x=x, colour = g)) + stat

Add custom legend without any relation to the graph

依然范特西╮ 提交于 2019-11-27 02:32:22
问题 I wish to insert a legend that is not related to the graph whatsoever: figure; hold on; plot(0,0,'or'); plot(0,0,'ob'); plot(0,0,'ok'); leg = legend('red','blue','black'); Now I wish to add it to another figure: figure; t=linspace(0,10,100); plot(t,sin(t)); %% ADD THE LEGEND OF PLOT ABOVE 回答1: This is how I have solved this problem in the past: figure t=linspace(0,10,100); plot(t,sin(t)); hold on; h = zeros(3, 1); h(1) = plot(NaN,NaN,'or'); h(2) = plot(NaN,NaN,'ob'); h(3) = plot(NaN,NaN,'ok')

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 change legend size with matplotlib.pyplot

泄露秘密 提交于 2019-11-27 02:25:22
Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc=2) Yann You can set an individual font size for the legend by adjusting the prop keyword. plot.legend

How can I make a fieldset legend-style “background line” on heading text?

走远了吗. 提交于 2019-11-27 01:52:13
I'm attempting to style heading text similar to how your default legend text appears in fieldsets; that is to say, I'd like a strikethrough-like line to come up to, but not through, the text. I can't seem to find any information on how I might accomplish this, and since on numerous other questions Google's always directed me to Stack Overflow for answers, I thought someone here may be able to give me advice. For greater clarity. I'm attempting to get this effect on header text: Centered Header Text Is there any way to do this? See: http://jsfiddle.net/thirtydot/jm4VQ/ If the text needs to wrap