legend

Plot labels at ends of lines

僤鯓⒐⒋嵵緔 提交于 2019-11-26 04:09:49
问题 I have the following data ( temp.dat see end note for full data) Year State Capex 1 2003 VIC 5.356415 2 2004 VIC 5.765232 3 2005 VIC 5.247276 4 2006 VIC 5.579882 5 2007 VIC 5.142464 ... and I can produce the following chart: ggplot(temp.dat) + geom_line(aes(x = Year, y = Capex, group = State, colour = State)) Instead of the legend, I\'d like the labels to be coloured the same as the series to the right of the last data point for each series I\'ve noticed baptiste\'s comments in the answer in

Add legend to scatter plot (PCA)

依然范特西╮ 提交于 2019-11-26 04:01:36
问题 I am a newbie with python and found this excellent PCA biplot suggestion (Plot PCA loadings and loading in biplot in sklearn (like R's autoplot)). Now I tried to add a legend to the plot for the different targets. But the command plt.legend() doesn\'t work. Is there an easy way to do it? As an example, the iris data with the biplot code from the link above. import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from sklearn.decomposition import PCA import pandas as pd

Is there a way to change the spacing between legend items in ggplot2?

拟墨画扇 提交于 2019-11-26 03:49:16
问题 Is there a way to change the spacing between legend items in ggplot2? I currently have legend.position =\"top\" which automatically produces a horizontal legend. However, the spacing of the items is very close together and I am wondering how to space them farther apart. 回答1: ggplot2 v3.0.0 released in July 2018 has working options to modify legend.spacing.x , legend.spacing.y and legend.text . Example: Increase horizontal spacing between legend keys library(ggplot2) ggplot(mtcars, aes(factor

Moving matplotlib legend outside of the axis makes it cutoff by the figure box

淺唱寂寞╮ 提交于 2019-11-26 03:02:06
问题 I\'m familiar with the following questions: Matplotlib savefig with a legend outside the plot How to put the legend out of the plot It seems that the answers in these questions have the luxury of being able to fiddle with the exact shrinking of the axis so that the legend fits. Shrinking the axes, however, is not an ideal solution because it makes the data smaller making it actually more difficult to interpret; particularly when its complex and there are lots of things going on ... hence

Add a common Legend for combined ggplots

梦想与她 提交于 2019-11-26 02:48:20
I have two ggplots which I align horizontally with grid.arrange . I have looked through a lot of forum posts, but everything I try seem to be commands that are now updated and named something else. My data looks like this; # Data plot 1 axis1 axis2 group1 -0.212201 0.358867 group2 -0.279756 -0.126194 group3 0.186860 -0.203273 group4 0.417117 -0.002592 group1 -0.212201 0.358867 group2 -0.279756 -0.126194 group3 0.186860 -0.203273 group4 0.186860 -0.203273 # Data plot 2 axis1 axis2 group1 0.211826 -0.306214 group2 -0.072626 0.104988 group3 -0.072626 0.104988 group4 -0.072626 0.104988 group1 0

Control ggplot2 legend look without affecting the plot

只谈情不闲聊 提交于 2019-11-26 02:18:15
问题 I\'m plotting lines with ggplot2 like this: ggplot(iris, aes(Petal.Width,Petal.Length,color=Species)) + geom_line() + theme_bw() . I find legend marks to be small so I want them to be bigger. If I change the size, lines on the plot change too: ggplot(iris, aes(Petal.Width,Petal.Length,color=Species)) + geom_line(size=4) + theme_bw() . But I only want to see thick lines in the legend, I want lines on the plot to be thin. I tried to use legend.key.size but it changes the square of the mark, not

Secondary axis with twinx(): how to add to legend?

江枫思渺然 提交于 2019-11-26 01:43:49
问题 I have a plot with two y-axes, using twinx() . I also give labels to the lines, and want to show them with legend() , but I only succeed to get the labels of one axis in the legend: import numpy as np import matplotlib.pyplot as plt from matplotlib import rc rc(\'mathtext\', default=\'regular\') fig = plt.figure() ax = fig.add_subplot(111) ax.plot(time, Swdown, \'-\', label = \'Swdown\') ax.plot(time, Rn, \'-\', label = \'Rn\') ax2 = ax.twinx() ax2.plot(time, temp, \'-r\', label = \'temp\')

Add a common Legend for combined ggplots

*爱你&永不变心* 提交于 2019-11-26 00:57:16
问题 I have two ggplots which I align horizontally with grid.arrange . I have looked through a lot of forum posts, but everything I try seem to be commands that are now updated and named something else. My data looks like this; # Data plot 1 axis1 axis2 group1 -0.212201 0.358867 group2 -0.279756 -0.126194 group3 0.186860 -0.203273 group4 0.417117 -0.002592 group1 -0.212201 0.358867 group2 -0.279756 -0.126194 group3 0.186860 -0.203273 group4 0.186860 -0.203273 # Data plot 2 axis1 axis2 group1 0

Add legend to ggplot2 line plot

我与影子孤独终老i 提交于 2019-11-25 21:49:59
问题 I have a question about legends in ggplot2. I managed to plot three lines in the same graph and want to add a legend with the three colors used. This is the code used library(ggplot2) require(RCurl) link<-getURL(\"https://dl.dropbox.com/s/ds5zp9jonznpuwb/dat.txt\") datos<- read.csv(textConnection(link),header=TRUE,sep=\";\") datos$fecha <- as.POSIXct(datos[,1], format=\"%d/%m/%Y\") temp = ggplot(data=datos,aes(x=fecha, y=TempMax,colour=\"1\")) + geom_line(colour=\"red\") + opts(title=\"TITULO

How to put the legend out of the plot

萝らか妹 提交于 2019-11-25 21:41:25
问题 I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure gets reduced. Kindly help me for the following queries: I want to keep the legend box outside the plot area. (I want the legend to be outside at the right side of the plot area). Is there anyway that I reduce the font size of the text inside the legend box, so that the size of the legend box will be