legend

Custom legend with imported images

末鹿安然 提交于 2019-11-28 10:36:10
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. 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 functions to locate the viewports containing the legend key grobs, and replaces one with the R logo library(png)

How to add a legend to matplotlib pie chart?

旧街凉风 提交于 2019-11-28 10:16:24
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: UTF-8 -*- import matplotlib.pyplot as plt # The slices will be ordered and plotted counter-clockwise.

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

五迷三道 提交于 2019-11-28 10:02:37
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, pointsize=10) ggplot(data.frame(x=c(0,80)),aes(x) ) + stat_function(fun=function(x)((1-Fm1(x)) - (1- Fm0(x))

Tab alignment in legend of Matplotlib Plot

喜夏-厌秋 提交于 2019-11-28 09:52:07
问题 I would like to create a plot with a legend aligning the text of the different curves. Here is a minimal working example: import matplotlib.pyplot as plt import numpy as np x=np.linspace(0,10,100) plt.plot(x,np.sin(x),'-',label=r'1st, second, third, a$_b$') plt.plot(x,np.cos(x),'--',label=r'fourth, 5th, 5$_{fo}$, sixth') plt.legend() plt.show() I want the labels to align in the legend, so get something like: 1st second third a$_b$ fourth 5th 5$_{fo}$ sixth Is there a way of doing this? 回答1:

How to disable legend in nvd3 or limit it's size

倾然丶 夕夏残阳落幕 提交于 2019-11-28 09:42:32
I'm using nvd3 and have a few charts where the legend is much to large. E.g. a scatter/bubble with 15 groups and the group names are long. The legend is so large that it leaves almost no room for the chart itself. Is there a way to remove the legend or toggle the legend or limit the height/width it is taking up? Any example would be great. Also, is there a way to have the bubble show a descriptive string? Right now when you stand on top of a bubble it highlights the x/y coordinates. I also want it to show the bubble name. For example, each of my bubbles represents a country (which has a name),

How to show abline of geom_abline in legend

蓝咒 提交于 2019-11-28 09:27:37
问题 in the following sample data , how can i display the abline ( i e the red color line) in legend with y. my code and data: x<-c(1990,1991,1992,1993,1994,1995) y<-c(400,500,465,450,550,555) df<-data.frame(x,y) df plot1<- ggplot(df, aes(x)) + geom_line(size=0.5,lty="dashed", aes(y=y),color="Blue") + geom_abline(aes(slope=-0.62,intercept=1670,colour="break"),size=0.9)+ geom_point(aes(y=y,shape="y"),size=4, color="Gray24",fill="Green") plot1 . what i got is the below image. i need the red line to

ggplot2 add a legend for several stat_functions

吃可爱长大的小学妹 提交于 2019-11-28 09:10:48
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") Try this: ggplot(NULL, aes(x=x, colour = g)) + stat_function(data = data.frame(x = 1:5, g = factor(1)), fun = myfun1) + stat_function(data = data.frame(x = 1:5,

How to change font family in a legend in an R-plot?

旧时模样 提交于 2019-11-28 09:10:48
I have a graph use the base graphics package. For the labels on specific points I use text(i, MSSAcar$summary[i,7]+.7, qld$LGA[i], col='red', cex=.7, family='serif') I have also used this in the plot for main titles and axis labels. They all come out as expected. When I add a legend I cannot seem to be able to set the font family. Can anyone help please. Thanks. Set the family plotting parameter before calling legend() to the value you want. Do this via an explicit call to par() . Here is a simple example x <- y <- 1:10 plot(x, y, type = "n") text(x = 5, y = 5, labels = "foo", family = "serif"

Add custom legend without any relation to the graph

孤街醉人 提交于 2019-11-28 08:59:18
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 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'); legend(h, 'red','blue','black'); This will plot the additional points, but because the coordinates are at

ggplot2 draws two legends

混江龙づ霸主 提交于 2019-11-28 08:48:39
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 = structure(c(2L, 2L, 2L, 1L, 1L, 1L), .Label = c("Significant", "Zscore"), class = "factor"), Score = c(8.798129