legend

Image vs ggplot: how to plot color legend?

谁说我不能喝 提交于 2019-12-21 05:37:10
问题 Hi I have a matrix 37x73 that represent one variable (moavg) gridded with a 10x10 deg spacing (-180< LON< 180 e -90 < LAT< 90). I am able to plot it using image image(LON, LAT, moavg) but I can't display the colour bar. I would like to know if there is another function to do that (maybe ggplot) that allows me also to plot the colour legend. Many thanks 回答1: For plotting gridded spatial data, the raster and rasterVis packages are also useful. Here are a couple of examples: library(rasterVis) #

Centring legend below two plots in r

荒凉一梦 提交于 2019-12-21 05:35:12
问题 I would like to centre a common legend below two plots. I have used xpd=TRUE to allow for printing outside the plot itself and oma to create space for the legend. However the legend will not move horizonatally and gets clipped 'early' vertically. Any advice? quartz(title="PCoA",12,6) par(mfrow=c(1,2),oma=c(5,0,0,0),xpd=TRUE) plot(1:3,4:6,main="plot 1") plot(1:3,4:6,main="plot 2") # Clips the plot legend(1,3.5,ncol=3,c("0-1 km","1-5 km","outside barrier"),fill=c("green","orange","red"), title=

Add table (aligned text blocks) to plot in R

一曲冷凌霜 提交于 2019-12-21 03:57:13
问题 I'd like to add a small table (for example as a legend) to a plot in R . I think of something like: t <- wantedTableMethod( row("param1", "param2", "param3", "param4") , row(value11, value12, value13, cell(value14, adj=0)) , row(value21, value22, value23, value24) , row(value31, value32, value33, cell(value34, adj=1)) border = F ) plot(1,1) legend("topleft", t) All values of a column should have the same offset. Is something like this possible in R , or do I need to align each value manually?

How to tell legends from axes in Matlab?

[亡魂溺海] 提交于 2019-12-21 01:12:12
问题 The following stackoverflow qestion: Matlab: How to obtain all the axes handles in a figure handle? identifies how to get handles to all of the axes from a figure in Matlab. However, this list will also contain handles to legends, at least in R2008a, which appear to also be axes. How can I tell (programatically) the legends from the real plot axes in a vector of axes handles? 回答1: From linkaxes , the code you want is: ax = findobj(gcf,'type','axes','-not','Tag','legend','-not','Tag','Colorbar

How to tell legends from axes in Matlab?

这一生的挚爱 提交于 2019-12-21 01:12:09
问题 The following stackoverflow qestion: Matlab: How to obtain all the axes handles in a figure handle? identifies how to get handles to all of the axes from a figure in Matlab. However, this list will also contain handles to legends, at least in R2008a, which appear to also be axes. How can I tell (programatically) the legends from the real plot axes in a vector of axes handles? 回答1: From linkaxes , the code you want is: ax = findobj(gcf,'type','axes','-not','Tag','legend','-not','Tag','Colorbar

R: creating vectors of latin/greek expression for plot titles, axis labels, or legends

偶尔善良 提交于 2019-12-20 21:58:35
问题 I would like to merge vectors of Latin and Greek text to generate plot titles, axis labels, legend entries, etc. I have provided a trivial example below. I cannot figure out how to render the Greek letters in their native form. I have tried various combinations of expression , parse , and apply to the paste command but I have not been able to vectorize the code that readily generates mixed Latin/Greek text for the case of a single expression (e.g., expression("A ("*alpha*")") is suitable in

Add pch symbol in R plot legend

不问归期 提交于 2019-12-20 17:35:16
问题 I have one time series which is represented by a black line and one which is represented by a red curve. Then I have single points which have the pch symbol of 8 in R. These are stars. See the following plot: Currently I have the following legend: legend("bottomleft", legend=c("log loss","daily VaR","exceedance"), bty = "n",lwd=2, cex=1.2,y.intersp=1.4, col=c("black","red","blue"), lty=c(1,1,1)) But I don't want to have a blue line in the legend for exceedance, but just the stars in the plot.

R - adding legend to ggmap (ggplot2) while using annotate

旧街凉风 提交于 2019-12-20 17:28:54
问题 FYI: I'm fairly new to ggplot2 and ggmap so I apologize for the sloppy code but it is the only way I've been able to plot sets of groups of points where each group has it's own color. Also my os is ubuntu. I'm trying to add a legend, to a ggmap object and in particular a legend with a continuos gradient transitioning the colors. Any advice? I've tried the legend attribute in ggmap but it doesn't seem to be working. Below is what I have so far. syd = get_map(location = center, zoom = zoom,

R - adding legend to ggmap (ggplot2) while using annotate

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 17:27:56
问题 FYI: I'm fairly new to ggplot2 and ggmap so I apologize for the sloppy code but it is the only way I've been able to plot sets of groups of points where each group has it's own color. Also my os is ubuntu. I'm trying to add a legend, to a ggmap object and in particular a legend with a continuos gradient transitioning the colors. Any advice? I've tried the legend attribute in ggmap but it doesn't seem to be working. Below is what I have so far. syd = get_map(location = center, zoom = zoom,

How to change the text colour of font in legend?

喜你入骨 提交于 2019-12-20 17:26:58
问题 Is there a way to change the font colour of the legend in a matplotlib plot? Specially in occasions where the background of the plot is dark, the default black text in the legend is hard or impossible to read. 回答1: call Legend.get_texts() will get a list of Text object in the legend object: import pylab as pl pl.plot(randn(100), label="randn") l = legend() for text in l.get_texts(): text.set_color("red") 回答2: You can also do it with setp(): import pylab as plt leg = plt.legend(framealpha = 0,