Tag: plot

如何更改ggplot中的图例标题

我有下面的情节如下。 它是用这个命令创build的: >library(ggplot2) >df <- data.frame(cond = factor( rep(c("A","B"), each=200) ), rating = c(rnorm(200),rnorm(200, mean=.8))) >ggplot(df, aes(x=rating, fill=cond)) + geom_density(alpha=.3)+xlab("NEW RATING TITLE")+ylab("NEW DENSITY TITLE") 现在接下来我要做的就是将cond的图例标题修改为NEW LEGEND TITLE 。 所以我所做的只是添加以下代码添加上面代码的结尾: +labs(colour="NEW LEGEND TITLE") 但它不起作用。 什么是正确的方法来做到这一点?

使用ggplot进行绘图时,hjust和vjust会做什么?

每次我使用ggplot做一个情节,我花了一点时间,尝试不同的值为hjust和vjust在一行 + opts(axis.text.x = theme_text(hjust = 0.5)) 使轴标签与轴标签几乎接触到轴的位置alignment,并与之alignment(可以说与轴alignment)。 但是,我不太明白发生了什么事。 通常情况下, hjust = 0.5给出了如此显着不同的结果,例如,我不能仅仅通过玩弄不同的值来解决这个问题。 任何人都可以点我全面解释如何调整和调整选项的工作?

如何将图像保存为磁盘上的图像?

我使用R绘制了一个简单的线性回归。我想将该图像保存为PNG或JPEG,是否可以自动执行? (通过代码) 有两个不同的问题:首先,我已经在看我的显示器上的情节,我想保存它。 其次,我还没有生成剧情,但我想直接保存到磁盘上,当我执行我的绘图代码。

matplotlib savefig()与show()不同

当我使用show()来绘制X中的图时,图看起来非常好。 但是,当我开始使用savefig()生成大量的graphics时, savefig()生成的graphics的字体,线条,多边形都比show()生成的graphics小。 我的环境是Ubuntu和show()的后端是Qt4Agg 。 如何使show()图和savefig()图看起来一致?

使用ggplot2在地图上绘制条形图?

我想使用ggplot2为地图上的每个位置生成一个barplot,就像xm根据基础graphics和一些包所做的那样: Let R fly: Visualizing Export Data using R 这与在情节中embedded微型情节有关。 目前,我能做的最好的事情就是在抖动点图上匹配点的大小。 require(ggplot2) require(maps) #Get world map info world_map <- map_data("world") #Creat a base plot p <- ggplot() + coord_fixed() #Add map to base plot base_world <- p + geom_polygon(data=world_map, aes(x=long, y=lat, group=group)) #Create example data geo_data <- data.frame(long=c(20,20,100,100,20,20,100,100), lat=c(0,0,0,0,0,0,0,0), value=c(10,30,40,50,20,20,100,100), Facet=rep(c("Facet_1", "Facet_2"), 4), colour=rep(c("colour_1", "colour_2"), each=4)) […]

如何为域和范围轴JFreeChart设置相同的比例

我想创build类似于极点/零点图的极点/零点图 。 它是显示IIR和FIR滤波器的性能,如稳定性,types… 我的问题是:如何为两个轴设置相同的比例(不是范围)? 我使用ScatterPlot绘制图表。 JFreeChart chart = ChartFactory.createScatterPlot("Pole/zero plot", // chart // title "real", // x axis label "imaginary", // y axis label result, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelsVisible(true, […]

如何删除ggplot2中轴与面积图之间的空间?

我有以下数据框: uniq <- structure(list(year = c(1986L, 1987L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 1986L, 1987L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, […]

将geom_text定位在闪避的barplot上

我试图让这个标题不言自明,但是数据优先: dtf <- structure(list(variable = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L), .Label = c("vma", "vla", "ia", "fma", "fla"), class = "factor"), ustanova = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("srednja škola", "fakultet"), class = "factor"), `(all)` = c(42.9542857142857, 38.7803203661327, 37.8996138996139, 33.7672811059908, 29.591439688716, 26.1890660592255, 27.9557692307692, 23.9426605504587, […]

在一个图表中绘制多个boxplot

我将数据保存为12列的.csv文件。 列2到11(标记为F1, F2, …, F11 )是features 。 Column one包含这些function的bad label 。 我想绘制所有这11个特征与boxplot ,但分别是good还是bad 。 我的代码到目前为止是: qplot(Label, F1, data=testData, geom = "boxplot", fill=Label, binwidth=0.5, main="Test") + xlab("Label") + ylab("Features") 但是,这只能显示F1对label 。 我的问题是:如何显示F2, F3, …, F11对一个图中的label与一些dodge position ? 我已经对这些特征进行了归一化处理,因此它们在[0 1]范围内处于相同的范围内。 testing数据可以在这里find。 我画了一些东西来解释这个问题(见下文)。

在R图窗口中结合base和ggplotgraphics

我想生成一个具有基本和ggplotgraphics组合的graphics。 以下代码显示了使用R的基本绘图函数的graphics: t <- c(1:(24*14)) P <- 24 A <- 10 y <- A*sin(2*pi*t/P)+20 par(mfrow=c(2,2)) plot(y,type = "l",xlab = "Time (hours)",ylab = "Amplitude",main = "Time series") acf(y,main = "Autocorrelation",xlab = "Lag (hours)", ylab = "ACF") spectrum(y,method = "ar",main = "Spectral density function", xlab = "Frequency (cycles per hour)",ylab = "Spectrum") require(biwavelet) t1 <- cbind(t, y) […]