FAQ Database Discussion Community


Dynamically create expression for ggplot legend?

r,ggplot2,expression,legend
I want to plot a line graph, with multiple lines, coloured depending on a grouping variable. Now I want to set the legend labels via scale-command: scale_color_manual(values = colors_values, labels = ...) The legend labels are as following: "x^2", "x^3", "x^4" etc., where the range is dynamically created. I would...

How to hide one series data info in tooltip using highcharts

highcharts,hide,legend,series
Hi I am getting a following chart: I want to hide the water info from the tooltip. How can I do that. You can use the following fiddle to play with it. Thanks!!!...

Creating Variables with Group in R igraph2

r,legend,igraph
in the link is my previous question and codes about igraph in R Creating Variables with Group in R igraph My question now is why the arrow head in the example are small while mine are big like this: How can I reshape the arrow to look like the answer...

How to add three legends of a bar graph in matlab?

matlab,plot,bar-chart,legend,precision-recall
i have a bar graph which calculates precession and recall for three different methods and represents them in three different colors, code i used is as follows x=[0.4,0.31,0.21] y=[0.45,0.38,0.27] bar(x,y,0.1) h = bar(x,diag(y),0.1,'stacked'); xlabel('precession') ylabel('recall') i want to add a legend that should show maroon color is for indiscernible relation,...

Set plot legend manually / change order

matlab,plot,legend
following problem: I have 5000 two dimensional (x/y) Datapoints which consist of 10 different classes. (Stored in an 5000x2 matrix) All datapoints are plottet in one figure, each class got his own color/marker style. The order of the Datapoints is random! (So maybe it starts with a point out of...

seaborn: legend with background color

python,plot,legend,seaborn
The following question explains how to change the background color of a legend: matplotlib legend background color. However, if I use seaborn this does not work. Is there a way to do this? import matplotlib.pyplot as plt import numpy as np a = np.random.rand(10,1) plt.plot(a, label='label') legend = plt.legend() frame...

add legend matlab plot

matlab,plot,add,legend
I have a matlab function myfunction(var1,var2) which gives me a plot with a legend. I would like to generate more plots with this function in one graph. This works so far i.e. for 2 plots in one graph with: myfunction(a,b) hold on myfunction(c,d) hold off The problem here is that...

Greek letters in legend in R

r,expression,legend
I want to have three curves on the same plot with different parameter alpha. curve(sin(x), from = 1, to = 3, lty = 1, ylim = c(-1, 1)) curve(sin(2 * x), add = TRUE, lty = 2) curve(sin(3 * x), add = TRUE, lty = 3) legend("topright", legend = expression(paste(alpha,...

R : legend() error

r,plot,legend
I'm trying to generate a legend for a plot to show the colors' relationships to cluster # in a plot. I don't actually need it in the plot I just want to generate a legend then copy and paste it into a powerpoint slide. I found this code here that...

One combined legend entry for multiple plots

matlab,plot,legend,matlab-figure
For some reason, I would like to plot the line and marker of the same data separately. data1 = (1:1:10)'; data2 = (1:2:10); figure(1); plot(data1,data1,'or'); hold on; plot(data2,data2,'-r'); legend('data'); However it will only display the legend for the first plot. And Matlab seems not to have option to manipulate the...

Python Scatter Plot with Colorbar and Legend Issues

python,matplotlib,legend,scatter-plot
I'm working with a pretty simple example. I create three scatter plots on the same set of axes, and each data set I plot has a different associated colormap. However, the legend does not look as I'd want it to; why is this? import numpy as np import matplotlib.pyplot as...

Plot monthly Time series from a data frame with daily data

r,plot,time-series,legend
I have a data set for motor vehicle crashes happening daily in NYC from 1 Jan 2014 to 31 Dec 2012. I want to plot time series of the number of injured cyclists, and motorists, monthly in a single plot. My data looks like this: Date Time Location Cyclists injured...

Positioning legend on plot divided by par(mfrow) in R

r,legend
I have my plot window divided using par(mfrow=c(2,4)) I have 7 plots and would like to use the remaining plot space to write the legend (i.e. the blank space in the bottom right hand corner) I was wondering is there an easy way to put the legend into this position?...

matplotlib legend shows “Container object of 10 artists” instead of label

matplotlib,legend
The code below produces the plot and legend correctly, however the legend does not show the specified label text, but "Container object of 10 artists" instead. ax = plt.subplot(212) plt.tight_layout() l1= plt.bar(X+0.25, Y1, 0.45, align='center', color='r', label='A', edgecolor='black', hatch="/") l2= plt.bar(X, Y2, 0.45, align='center', color='b', label='N',hatch='o', fill=False) ax.autoscale(tight=True) plt.xticks(X, X_values)...

ggplot Legend Bar and Line in Same Graph

r,ggplot2,legend
I'm plotting a bar graph and a line graph on the same chart, and I was wondering if there was a way to have the legend for ggplot say that the bar is for one thing, and the line is for another. That is, rather than identifying what they fill...

personalize legend in jchart2d

java,legend,jchart2d
I want to personalize the legend in a graph created in jchart2d. At the moment i can get a legend like the one in the left graph in the image, i want something like the legend in the right graph. Is this possible with jchart2d or i have to use...

Legend in gplotmatrix

matlab,data,plot,legend,legend-properties
Given an N x M feature matrix featMat (for M features and N samples) and an N x 1 class vector classVec we can nicely visualize this multivariate data with the help of gplotmatrix. Example: featMat = rand(10,3); classVec = rand(10,1) > 0.3; gplotmatrix(featMat, [], classVec, ['g','r']); My Question: How...

gnuplot: add extra keys

key,gnuplot,histogram,legend
I have a simple gnuplot script to plot a histogram with differently colored bars, with each color representing a group. How can I show 3 different keys (1 red, 1 green and 1 blue)? This is my script: unset title set key left set yrange [0:10] set ylabel 'Score' set...

Legend showing an unexpected black line with geom_vline

r,ggplot2,legend
I have been trying to add an additional legend after looking at some of the answers provided at StackOverflow but somehow I can't make this work. I'm using the following code: x_breaks <- seq(as.Date("2010/1/1"), as.Date("2015/4/1"), "months") x_labels <- as.character(x_breaks, format="%b%y") vLines <- data.frame('Date'=as.Date('2014/1/1')) vLines <- rbind(vLines,vLines,vLines,vLines) vLines$Date[1] <- as.Date('2010/6/7') vLines$Date[2]...

How do I use the element with styles?

html,css,legend
I just ran into a quirky problem and haven't been able to find an answer or figure it out. The problem is regarding the <legend> tag within a <form>. I've created a form using <form> and when I use <fieldset> with <legend> nested inside, the page renders normally, just fine!...

Dynamic FLOT legend table

javascript,jquery,css,flot,legend
I have a somewhat limited knowledge of JS and JQuery so I am sorry if this is a stupid question. I have a dashboard of charts which will have varying widths and also allows a user to change the width. The chart automatically adjusts it's size. What I want is...

ggplot2: When overlapping two plots to get axes on the right, legend from second plot isn't displayed

r,plot,ggplot2,legend,axis-labels
I am using the ggplot_dual_axis() function from the Stack Overflow answer at How can I put a transformed scale on the right side of a ggplot2? in order to display two Y axes, one on the right and one on the left. The function is a big hacky mess that...

fine-grained colour gradient legend

r,gradient,legend
I have a problem when making a colour gradient legend. In my case the data can range from 0 to 1, and the differences between values can be very small, making the legend look more or less unicolour. Is there a way to make the gradient more fine-grained? #dummy data...

“None” in legend pandas python

excel,python-2.7,pandas,legend
I am using WinPython Notebook with Python 2.7. So I am reading several DataFrames like this: run[y2][y3][x] = pd.read_excel(xls_file, x) When then I use: run[y2][y3][x].plot() I get nice plot with 3 lines and a legend describing these lines as it is in the excel file on the top of the...

Remove the line and the background in the two legends

r,ggplot2,legend,geom-bar
I made this plot: #data sal<-data.frame(x=factor(c(2,2,1,1),labels=c('House','Work'))) sal$id<-factor(c(2,1,2,1),labels=c('t0','t1')) sal$val<-c(305,280,290,180) sal$lim1<-c(75,75,150,150) sal$lim2<-c(150,150,300,300) #plot p<-ggplot(sal,aes(id,y=val,fill=id))+ geom_bar(stat="identity",position="dodge",width=.75)+ scale_fill_brewer(palette='Set1',type='qual',name='Time')+ theme(axis.title.x=element_blank(), axis.title.y=element_blank(),...

Scatterplot with two legends with corresponding colors

r,plot,ggplot2,legend,word-cloud
I've got the following plot: So I've got two groups of words that I've coloured in red and blue. Besides that I've got two legends where each legend corresponds to one group. My code is as follows: install.packages("wordcloud") library(wordcloud) textplot(cor_met_u1, cor_met_u2, 1:length(cor_met_u1) ,ylim=c(-1,1), xlim=c(-1,1), col ="red", show.lines=F) par(new=T) textplot(cor_met_v1, cor_met_v2,...

Filter (no display) layers in GeoExt.LegendPanel using LIKE operator [closed]

filter,panel,openlayers,legend,geoext
This works to avoid Basemap layers such as Google Maps and overlays such as WMS to appear in the GeoExt Legend Panel: var legendPanel = new GeoExt.LegendPanel({ border: false, filter: function(record){ if(!(record.getLayer().isBaseLayer) && (record.getLayer() instanceof OpenLayers.Layer.WMS)){ return true; } } }); The problem is that I need to filter (ie....

How to add legend for vertical lines in ggplot?

r,ggplot2,legend
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)...

Changing the legend labels in a windrose from R openair

r,legend
I made a graph using windRose from the openair package. Here is a reproducible example. library(openair) windRose(mydata, ws="ws", wd="wd", breaks=c(0,1.5,3.3,5.4,7.9,10.7), auto.text= FALSE, paddle = FALSE, annotate = FALSE) I found that I can change the legend title, footer and position by key.header, key.footer and key.position. But I would like to...

Create abbreviated legends manually for long X labels in ggplot2

r,ggplot2,legend
I would like to create a simple bar chart with ggplot2 and my problem is that my x variable contains long strings so the labels are overlaid. Here are fake datas and the plot : library(dplyr) library(tidyr) library(ggplot2) set.seed(42) datas <- data.frame(label = sprintf("aLongLabel%d", 1:8), ok = sample(seq(0, 1, by...

Highcharts Donutchart: Avoid showing duplicate legend with nested charts

javascript,highcharts,legend,pie-chart
I am trying to represent nested data using Highcharts Donut Chart. The charts are generated quite well, however I am having some problems with displaying the legend. Data to be represented: Category A -[High : 20%, | Medium : 50% | Low : 30%] Category B -[High : 10% |...

Turn long list of items in Highcharts legend into dropdown

javascript,highcharts,legend
I have a graph with some 40 items as separate lines. Now, I need to add the functionality of turning on/off or highlighting any of these via legend/menu/dropdown list. Normally, when the legend is turned on, I can click on any item and turn it on/off there. However, the very...

Extjs 5.1 chart legend

javascript,charts,legend,extjs5
I'm using Ext JS 5.1. I have a very simple problem: I have a pie chart, and a button. When I click on the button, I bind a new store to my chart. This works fine. But, if I make one element invisible in my chart (by clicking on one...

Customized Legend in Matlab

matlab,legend
Here I have a for loop to plot the content of my matrix. Based on 'type' value I determine the plot object (ks,bO,rX) for k = 1:length(data1) if(type(k)==1) h=plot(data1(k,1),data1(k,2),'ks');set(h,'linewidth',2);hold on; elseif(type(k) ==0) h=plot(data1(k,1),data1(k,2),'bO');set(h,'linewidth',2); hold on; else h=plot(data1(k,1),data1(k,2),'rX');set(h,'linewidth',2); hold on; end end I am little bit confused to find a way...

How to show tooltip on a Google Pie Chart on legend hover?

charts,google-visualization,legend,mousehover,legend-properties
I want to show the tooltip of the slices on the mouse hover in the legend. By default it shows the tooltip only when the mouse is over a slice of the pie. Currently the nearest thing I have is to show the tooltip when I click on the legend,...

Add a legend of colors in image {graphics}

r,colors,legend
In this example, I have an image with colors and I wonder if we can add a legend of colors. for example : points with z in [8:10] have color red and so on. x=runif(500,0,5) y=runif(500,0,5) z=floor(runif(500, 1,10)) xyz=data.frame(x,y,z) library(MBA) mba.int <- mba.surf(xyz, 300, 300, extend=T)$xyz.est image(mba.int, xaxs="i", yaxs="i") Thank...

Remove default alpha blending in legend key, change legend key titles

r,plot,legend,alpha
I have a visual of three different groups, that I have made into a scatterplot: dat = data.frame(x=rnorm(1000,0,1), y=rnorm(1000,0,1), cluster=sample(1:3, 1000,replace=TRUE)) ggplot(dat, aes(x,y)) + geom_point(aes(colour = factor(cluster)), alpha=0.3) + xlab("My x-axis") + ylab("My y-axis") + theme(legend.position="bottom") + theme(legend.text =element_text("Clusters")) + ggtitle("My title") The only things I could not get had...

R legend only showing first item

r,ggplot2,legend
Here is my R code and below is the resulting plot. ggplot(Data,aes(x=P, y=T, colour=Study , fill=Method, shape=Direction)) + geom_point(size=2, alpha=0.5) + scale_shape_manual(values=c(22,23,24),labels=c("1","2","3")) + scale_colour_manual(values=cp2,labels=cp2) + scale_fill_manual(values=c("white","black"),labels=c("1","2")) Why is the legend only showing the first value for shape and showing incorrect values for fill (the second should be empty)? Also, should...

Highcharts Legend item text alignment

highcharts,legend,jscript,legend-properties
I have the following problem: I would like to align the text of the legend in the following way: Legend: [Color1] Title1:---------------100.000.000€ [Color2] Title23343334:-----100.000.000€ [Color3] Title23343334:------10.000.000€ Do you know how can I do that?...

How to create legends with triangular end boxes in arcGIS?

legend,arcgis
I simply want my legend which is now in the form of the left bar in the following image, to be shown in the form of the bar in the right side. I couldn't find anything related for arcGIS. those anyone know? Thank you so much for your help....

Unable to customize legend in ggplot

r,ggplot2,legend
I am plotting yearly demand using ggplot (my code below) but I am not able to put color legend for the plot. My data.frame has "Zone" and "TotalDemand" (only 2 columns) and I have three data.frames for three years ("sales12", "sales13" and "sales14"). ggplot() + geom_point(data=sales12, aes(x=factor(Zone), y=TotalDemand/1000), color='green',size=6, shape=17)...

What do different icons and symbols in Android Studio's Structure sidebar mean?

android,android-studio,structure,legend,sidebar
When I click on 'Structure' sidebar in Android Studio, it displays the contents of the current class. However there are certain icons & symbols used to indicate different members, e.g., a circle with letter m for methods, etc. Where do I get the complete list and the details for all...

ggplot2 legend for abline and stat_smooth

r,ggplot2,legend
I have some problems with ggplot legends, here is my first code with only the legend for corrGenes, which is fine. gene1=c(1.041,0.699,0.602,0.602,2.585,0.602,1.000,0.602,1.230,1.176,0.699,0.477,1.322) BIME = c(0.477,0.477,0.301,0.477,2.398,0.301,0.602,0.301,0.602,0.699,0.602,0.477,1.176) corrGenes=c(0.922,0.982,0.934,0.917,0.993,0.697,0.000,0.440,0.859,0.788,0.912,0.687,0.894) DF=data.frame(gene1,BIME,corrGenes) plot= ggplot(data=DF,aes(x=gene1,y=BIME))+ geom_point(aes(colour=corrGenes),size=5)+ ylab("BIME normalized counts...

ggplot with extracting rows from data frame in for loop, showing different colors

r,for-loop,colors,ggplot2,legend
I have a data frame that contains monthly time series data (from jan 2010 through dec 2012). df<- data.frame(code=NA,Year=NA,Month=rep(seq(as.Date('2010/1/1'),by='month',length.out=36),3),x1=rnorm(3*36)) df$code[1:36]<-1; df$code[37:72]<-2; df$code[73:108]<-3 yr <- c(rep(2010,12),rep(2011,12),rep(2012,12)) df$Year<-rep(yr,3) I would like to extract the rows that have the same code (there will be 36 rows for each code), and plot the values...

Is it a bug in zingchart ( boxplot legend )

legend,boxplot,zingchart
I am trying to draw a boxplot using zingchart. I need a legend for the chart, but the legend generated is wrong. is it a bug in zingchart? Below is the json passed in: { "type": "boxplot", "vertical-labels": true, "legend":{}, "scale-x": { "labels": [] }, "series": [ { "data-box": [...

Generate a common legend (scale) for 2 rasters underneath the plots using scientific notation

r,plot,legend,raster,scientific-notation
I am trying to plot 2 rasters with different values with the same scale for comparison. I have been trying to work out the answer using this and this. I am running into two issues: I would like to be able to have the legend labels in scientific notation (there...

Duplicate legend with geom_vline() in ggplot

r,ggplot2,legend
I want to create this graphic: aux_graf = structure(list(lines = structure(c(2L, 2L, 1L, 3L), .Label = c("h0", "ic", "median"), class = "factor"), values = c(21.19755, 23.06978, 24, 22.13366)), .Names = c("lines", "values"), row.names = c(NA, -4L), class = "data.frame") dadosGraf = structure(list(dados = c(18.7997, 20.5035, 18.6214, 19.9192, 21.117, 20.8353, 17.527,...

pandas pie chart plot remove the label text on the wedge

pandas,matplotlib,legend,pie-chart
the pie chart example on pandas plotting tutorial http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html generates the following figure: with this code: import matplotlib.pyplot as plt plt.style.use('ggplot') import numpy as np np.random.seed(123456) import pandas as pd df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y']) f, axes = plt.subplots(1,2, figsize=(10,5)) for ax, col...

Pandas Matplotlib: How to change shape and size of the legend in scatter plot?

python,pandas,matplotlib,legend,scatter-plot
I have a scatter plot : fig,ax = plt.subplots(figsize=(6,5),dpi=200) ax.scatter(df1['id'],df1['resellers'],c='red',s=df1['ips']/80,label='AS Size = IPs seen in dnsdb') ax.set_xticks([1,2,4,6,8,10,12,14,16,18,20]) ax.set_xlim(-1,22) ax.legend( scatterpoints=1, loc='best', ncol=1, fontsize=12) I am wondering how can I change the shape and size of the bubble in the legend to rectangular and smaller size. Can anybody help?...

Create Customize legend for flot chart and get access to items after generation

jquery,charts,flot,legend,formatter
I have a graph using $.plot to created. I'm trying to use option values like 'series.percent' of chart for each data item. the reason behind that is I want to create a customized legend based on graph data.(for exp:show percentage in labelBox). Is it possible to do that? I 've...

matlab plots as movie with legend

matlab,plot,legend,movie
i have a question regarding legend for movies. This is my code: fig = figure(); for i = 1: 70000 plot(signal1) hold on; plot([i,i],[-5,5]) plot(signal2,'r') hold off; title('\fontsize{14} my data'); legend('signal1','signal2'); axis tight; f(i) = getframe(fig); end The legend shows the same colors for the first two things I plot....

Legend title position in

highcharts,legend
I'm using the legend title, but it's being positioned to the left and above the legend items: While I need it to be to the right, and on the same line as, the legend items: Legend title only accepts 2 properties - title and style,. Using style - I couldn't...

How to shift legend for discrete scales in ggplot?

r,ggplot2,legend
I have a data frame, called df, with 4 columns and 43010 lignes. The columns are X, Y, season, median. "X" and "Y" are lambert II coordinates of locations in France, "season" can have 5 values (Annual, Spring, Summer, Autumn and Winter), "median" is a number between -40 and 70...

Matplotlib automatic legend outside plot

python,matplotlib,plot,legend,legend-properties
I am trying to use the keyword bbox_to_anchor() in a matplotlib plot in Python. Here is a very basic plot that I have produced: import matplotlib.pyplot as plt x = [1,2,3] plt.subplot(211) plt.plot(x, label="test1") plt.plot([3,2,1], label="test2") plt.legend(bbox_to_anchor=(0, -0.15, 1, 0), loc=2, ncol=2, mode="expand", borderaxespad=0) plt.show() It is based on the...

want to add colored lines into complex plot legend

r,plot,legend
here is the code for the plot including the legend: png(filename=paste0(filename2, SubNameStr, "_", date, "_", BlankUncertainty, "-percent-blank-unc_", "no_add_unc", "_", " (R#_yyyy-mm-dd_hh-mm-ss).png"), type="cairo", units="cm", width=30, height=15, pointsize=12, res=resolution) par(mar =c(10, 4, 4, 2)+0.1) plotCI(1:abscissa, LoopVariable[ ,"F_corrected_normed"], xlim=c(0, abscissa + 1), ylim=c(LoopVariable[1,"weighted_mean_fraction_modern"] - (LoopVariable[1,"weighted_mean_fraction_modern"] * y),...

Different scatterplot markers with the same label

matplotlib,label,legend,scatter-plot,markers
I am having 'similar' issues to Matplotlib, legend with multiple different markers with one label. I was able to achieve the following thanks to this question Combine two Pyplot patches for legend. fig = pylab.figure() figlegend = pylab.figure(figsize=(3,2)) ax = fig.add_subplot(111) point1 = ax.scatter(range(3), range(1,4), 250, marker=ur'$\u2640$', label = 'S',...

How to selectively add box around legend key

r,ggplot2,legend
How could I add box around legend key only for color not for size while keeping both legend keys. Code below add boxes to both mappings. x<-1:6; y<-factor(2:7); z<-1:6; df <- data.frame(x,y,z) ggplot(df, aes(x,y)) + geom_point(aes(colour=y, size = z) ) + theme(legend.key = element_rect(colour = '#bdbdbd', size = 0.6)) ...

Matplotlib: Draggable is not working on multiple legends of plots which are generated with twinx()

python,matplotlib,plot,legend
I have two legends, as below, I find that I can't drag the first legend, what is the problem? how to deal with it? thanks! import matplotlib.pyplot as plt fig1, ax1 = plt.subplots() ax2 = ax1.twinx() ax1.plot([1,2,3],[0.1,0.82,0.3],'y*', label="one") ax2.plot([1,2,3],[5,6,7],'ro', label="two") leg1 = ax1.legend() leg2 = ax2.legend() leg1.draggable(state=True) leg2.draggable(state=True) plt.show() ...

colors in legend with many groups

r,plot,legend
I know it could be a simple question, but I'm really struggling.. Using the iris dataset as an example, I can use the following code to perform a plot with different colors depending on the different species: plot(iris$Sepal.Length, iris$Sepal.Width, col=iris$Species) legend('topright', legend=c("setosa", "virginica", "versicolor")) but actually I'm not able to...

Matlab plot legend automation

matlab,plot,legend,legend-properties
I am solving a pde that depends on x and t and would like to show the solution over all x for a few values of t. I am trying to write code that will automatically generate a legend for this plot. For example, if I am plotting the solution...

Plotting in MATLAB and legend

matlab,legend
Firstly, I'm trying to figure out a much more complicated situation, but this is the most minimal example I can provide. Suppose I want to present in a common figure the graphs of the 3 functions sinx, sin(2x), sin(3x) including their legends. I can draw the graphs in a common...

Changing legend using ggplot2

r,plot,ggplot2,legend
I have the following graph and I am trying to edit the legend so that the entries under Description have the colors reversed. For example, the BGM entry would have the black background switched to orange and the orange dash switched to a black dash. I would like to change...