legend

Label minimum and maximum of scale fill gradient legend with text: ggplot2

☆樱花仙子☆ 提交于 2019-11-28 19:31:40
I have a plot created in ggplot2 that uses scale_fill_gradientn . I'd like to add text at the minimum and maximum of the scale legend. For example, at the legend minimum display "Minimum" and at the legend maximum display "Maximum". There are posts using discrete fills and adding labels with numbers instead of text (e.g. here ), but I am unsure how to use the labels feature with scale_fill_gradientn to only insert text at the min and max. At the present I am apt to getting errors: Error in scale_labels.continuous(scale, breaks) : Breaks and labels are different lengths Is this text label

Edit seaborn legend

女生的网名这么多〃 提交于 2019-11-28 19:10:32
Using a data frame and this code in Python, I was able to create a plot: g = sns.lmplot('credibility', 'percentWatched', data=data, hue = 'millennial', markers = ["+", "."], x_jitter = True, y_jitter = True, size=5) g.set(xlabel = 'Credibility Ranking\n ← Low High →', ylabel = 'Percent of Video Watched [%]') However having the legend say "+ 0" and ". 1" isn't very helpful to readers. How can I edit the legend's labels? Ideally instead of saying 'millennial' it would say 'Generation' and "+ Millennial" ". Older Generations" If legend_out is set to True then legend is available thought g._legend

How can I remove the legend title in ggplot2?

风流意气都作罢 提交于 2019-11-28 18:31:56
I have a question concerning the legend in ggplot2. Say I have a hypothetical dataset about mean carrot length for two different colours at two farms: carrots<-NULL carrots$Farm<-rep(c("X","Y"),2) carrots$Type<-rep(c("Orange","Purple"),each=2) carrots$MeanLength<-c(10,6,4,2) carrots<-data.frame(carrots) I make a simple bar plot: require(ggplot2) p<-ggplot(carrots,aes(y=MeanLength,x=Farm,fill=Type)) + geom_bar(position="dodge") + opts(legend.position="top") p My question is: is there a way to remove the title ('Type') from the legend? Thanks! You can modify the legend title by passing it as the

How is order of items in matplotlib legend determined?

送分小仙女□ 提交于 2019-11-28 16:58:12
I am having to reorder items in a legend, when I don't think I should have to. I try: from pylab import * clf() ax=gca() ht=ax.add_patch(Rectangle((1,1),1,1,color='r',label='Top',alpha=.01)) h1=ax.bar(1,2,label='Middle') hb=ax.add_patch(Rectangle((1,1),1,1,color='k',label='Bottom',alpha=.01)) legend() show() and end up with Bottom above Middle. How can I get the right order? Is it not determined by creation order? Update: The following can be used to force the order. I think this may be the simplest way to do it, and that seems awkward. The question is what determines the original order? hh=

Concatenating 2D plots

人走茶凉 提交于 2019-11-28 14:24:15
I have several 2D-plots in MATLAB. In each plot there are some lines (each line is a row-vector of values of fixed length). There is always a base line (black one) and the remaining colored lines may or may not be present. , . I need to concatenate all such plots into one plot as shown below: Please note these are just for representational purpose but explain my problem well. I am not able to figure how to do it. Anybody got an idea? An example may be? Also, there has to be a vertical gap between the successively concatenated plots as is shown in last figure. Some points to note: y-axis is of

ggplot2: Change factor order in legend

醉酒当歌 提交于 2019-11-28 13:59:59
I have a a line graph and I want to reorder the way in which the factors appear in the legend. I have tried scale_fill_discrete but it doesn't change the order. Here's a simulation of my problem: df <- data.frame(var1=c("F", "F", "F", "B", "B", "B"), var2=c("levelB", "levelC", "levelA"), value=c("2.487585", "2.535944", "3.444764", "2.917308", "2.954155","3.739049")) p <- ggplot(data=df, aes(x=var1, y=value, group=var2, colour=var2, shape = var2)) + geom_line(size = 0.8) + geom_point()+ xlab("var1") + ylab("Value") + scale_x_discrete(limits=c("F","B")) + theme(legend.title = element_text(size

Make Chart Legend represent two colors

白昼怎懂夜的黑 提交于 2019-11-28 12:58:42
I created a column chart in my application which look like this: As you can see the positive values are green and the negative values are red. I need to represent this in the legend. I just don't know how. What I already tried: I added CustomItems to the Legend . Here is the code: Legend currentLegend = chart.Legends.FindByName(chart.Series[series].Legend); if (currentLegend != null) { currentLegend.LegendStyle = LegendStyle.Table; LegendItem li = new LegendItem(); li.Name = series; li.Color = Color.Red; li.BorderColor = Color.Transparent; currentLegend.CustomItems.Add(li); } This results in

tabular legend layout for matplotlib

ε祈祈猫儿з 提交于 2019-11-28 12:15:14
I have a plot with 9 lines, representing datasets with two varying parameters, say f_11, f_12, f_13, ..., f_33. To make the plot (a bit) clearer, I encode the first parameter as the color of the line and the second one as the linestyle (so f_11 is red & dashed, f12 is red & dotted, f21 is green & dashed, f22 is green & dotted, etc.). So, for the legend, I would like to make a 3x3 table, looking like | value1 | value2 | value3 --------------------------------- value1 | value2 | <artists go there> value3 | Is there any way I can make this with matplotlib? An idea would be to make this box with

How can I customize the positions of legend elements?

天涯浪子 提交于 2019-11-28 12:08:12
I have a figure with several plots and a legend. Is it possible to change the arrangement of the elements in the legend manually? For example, how could you make a two-column legend? Of course this is possible. See an explanation here: http://undocumentedmatlab.com/blog/multi-column-grid-legend/ To make a two-column legend, the general consensus seems to be that you need to create two separate legends and manually place them side by side. Solution simplified from discussion here . x = 1:10; y1 = rand(1, 10); y2 = rand(1, 10); h1 = plot(x, y1, '-'); hold on h2 = plot(x, y2, '-.r'); ah1 = gca;

Adjusting the width of legend for continuous variable

六眼飞鱼酱① 提交于 2019-11-28 11:59:33
I have a script below to illustrate my question: temp.df <- data.frame(x=1:100,y=1:100,z=1:100,stringsAsFactors=FALSE) chart <- ggplot(data=temp.df,aes(x=x,y=y)) chart <- chart + geom_line(aes(colour=z)) chart <- chart + scale_colour_continuous(low="blue",high="red") chart <- chart + theme(legend.position="bottom") # so far so good, but I think the legend positioned at bottom with such a small size is a waste of space, so I want to "widen" it using the line below... chart <- chart + guides(colour=guide_legend(keywidth=5,label.position="bottom")) # oops, it changed to legend for categorical