I have a plot where the x-axis is a factor whose labels are long. While probably not an ideal visualization, for now I'd like to simply rotate these labels to be vertical. I've figured this part out with the code below, but as you can see, the labels aren't totally visible. data(diamonds) diamonds$cut <- paste("Super Dee-Duper",as.character(diamonds$cut)) q <- qplot(cut,carat
我有一个情节,其中X轴是一个标签很长的因素。 虽然可能不是一个理想的可视化,但现在我想简单地将这些标签旋转为垂直。 我已经用下面的代码弄清楚了这一部分,但正如你所看到的,这些标签并不完全可见。 data(diamonds) diamonds$cut <- paste("Super Dee-Duper",as.character(diamonds$cut)) q <- qplot(cut,carat,data=diamonds,geom="boxplot") q + opts(axis.text.x=theme_text(angle=-90)) 将最后一行更改为 q +
I would like to place two plots side by side using the ggplot2 package, ie do the equivalent of par(mfrow=c(1,2)) . For example, I would like to have the following two plots show side-by-side with the same scale. x <- rnorm(100) eps <- rnorm(100,0,.2) qplot(x,3*x+eps) qplot(x,2*x+eps) Do I need to put them in the same data.frame? qplot(displ, hwy, data=mpg, facets = . ~ year) + geom_sm
我想使用ggplot2软件包并排放置两个图,即做相当于par(mfrow=c(1,2)) 。 例如,我希望以下两个图表以相同的比例并排显示。 x <- rnorm(100) eps <- rnorm(100,0,.2) qplot(x,3*x+eps) qplot(x,2*x+eps) 我是否需要将它们放在相同的data.frame中? qplot(displ, hwy, data=mpg, facets = . ~ year) + geom_smooth() 任何ggplots并排(或n个网格) gridExtra包中的函数grid.arrange()将组合多个图; 这就是你如何把
I have a question about creating ggplot2 graphs in a for loop, renaming them based on the iteration and then arranging the graphs in a grid. I want to do something like this dummy example library(ggplot2) a = c(1, 2, 3) b = c(4, 5, 6) for ( i in c(1:5)){ x = i*a y = i*b p = qplot(x, y) ... do something to rename p as plot_i... } ... do something to arranage plots plot_
我有一个关于在for循环中创建ggplot2图形的问题,根据迭代重命名它们,然后将这些图形排列在网格中。 我想要做这样的虚拟示例 library(ggplot2) a = c(1, 2, 3) b = c(4, 5, 6) for ( i in c(1:5)){ x = i*a y = i*b p = qplot(x, y) ... do something to rename p as plot_i... } ...做一些事情,以将plot_1 ... plot_6成2 x 3的网格 有什么建议么? 您可以将这些图保存到列表中: library(ggplo
I try to plot the same bar multiple times in the same graph using ggplot. My code (I want to plot Empetrum_ three times in the graph): temp10A <- ggplot(data, aes(x=Combination, y=Max.Max.Temp, fill=Combination)) + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(aes(ymin=Max.Max.Temp-se, ymax=Max.Max.Temp+se), width=.2, position=position_dodge(.9)) + scale_x_discret
我尝试使用ggplot在同一个图表中多次绘制相同的条形图。 我的代码(我想在图中绘制Empetrum_三次): temp10A <- ggplot(data, aes(x=Combination, y=Max.Max.Temp, fill=Combination)) + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(aes(ymin=Max.Max.Temp-se, ymax=Max.Max.Temp+se), width=.2, position=position_dodge(.9)) + scale_x_discrete(limits=c(**"Empetrum_"**, "Calluna_",
I plot a simple linear regression using R. I would like to save that image as PNG or JPEG, is it possible to do it automatically? (via code) There are two different questions: First, I am already looking at the plot on my monitor and I would like to save it as is. Second, I have not yet generated the plot, but I would like to directly save it to disk when I execute my plotting code. There a
我使用R绘制了一个简单的线性回归。我想将该图像保存为PNG或JPEG,是否可以自动执行此操作? (通过代码) 有两个不同的问题:首先,我已经在看我的显示器上的情节,我想保存它。 其次,我还没有生成剧情,但是当我执行我的绘图代码时,我想直接将它保存到磁盘。 有两个密切相关的问题,每个问题都有答案。 1.我的脚本将来会生成一个图像,我该如何将它保存到磁盘上? 要保存情节,您需要执行以下操作: 使用png()
As the title says: How can I plot a legend outside the plotting area when using base graphics? I thought about fiddling around with layout and produce an empty plot to only contain the legend, but I would be interested in a way using just the base graph facilities and eg, par(mar = ) to get some space on the right of the plot for the legend. Here an example: plot(1:3, rnorm(3), pch = 1, lty
正如标题所示: 使用基本图形时,如何在绘图区域外绘制图例? 我想过摆弄layout并产生一个只包含图例的空图,但我会对使用基图设施感兴趣,例如par(mar = )在图的右侧获得一些空间为传奇。 这里是一个例子: plot(1:3, rnorm(3), pch = 1, lty = 1, type = "o", ylim=c(-2,2)) lines(1:3, rnorm(3), pch = 2, lty = 2, type="o") legend(1,-1,c("group A", "group B"), pch = c(1,2), lty = c(1,2)) 生产: 但如前所述,
I have very large tables (30 million rows) that I would like to load as a dataframes in R. read.table() has a lot of convenient features, but it seems like there is a lot of logic in the implementation that would slow things down. In my case, I am assuming I know the types of the columns ahead of time, the table does not contain any column headers or row names, and does not have any pathological
我有非常大的表(3000万行),我想在R中加载一个数据read.table()有很多方便的功能,但是看起来好像有很多逻辑在执行时会减慢事情下降。 就我而言,我假设我提前知道列的类型,该表不包含任何列标题或行名称,并且没有任何我必须担心的病态字符。 我知道使用scan()作为列表在表中读取可能非常快,例如: datalist <- scan('myfile',sep='t',list(url='',popularity=0,mintime=0,maxtime=0))) 但是,我的一些尝试将其转换
Why is R inconsistent with the add parameter in the plot() function? It sometimes works and sometimes doesn't! In this example, it takes the parameter add=TRUE with no problem: plot(0:10, 0:10*3) plot(identity, add=TRUE, xlim=c(0,10)) plot(function (x) { sin(x)*10 }, add=TRUE, xlim=c(0,10)) But when I issue plot(c(2, 3, 4), c(20,10,15), add=TRUE, pch="A") It doesn't work!! It says
为什么R与plot()函数中的add参数不一致? 它有时有效,有时不起作用! 在这个例子中,它使用参数add=TRUE而没有问题: plot(0:10, 0:10*3) plot(identity, add=TRUE, xlim=c(0,10)) plot(function (x) { sin(x)*10 }, add=TRUE, xlim=c(0,10)) 但是当我问题 plot(c(2, 3, 4), c(20,10,15), add=TRUE, pch="A") 它不工作! 它说“添加”不是图形参数。 请不要写我应该使用points()来代替。 我知道我可以使用它。 我想了
Say have a Data.Frame object in R where all the character columns have been transformed to factors. I need to then "modify" the value associated with a certain row in the dataframe -- but keep it encoded as a factor. I first need to extract a single row, so here is what I'm doing. Here is a reproducible example a = c("ab", "ba", "ca") b = c("ab", "dd", "da") c = c("cd", "fa", "o
假设在R中有一个Data.Frame对象,其中所有字符列已被转换为因子。 然后,我需要“修改”与数据帧中某一行关联的值 - 但将其保留为一个因子编码。 我首先需要提取一行,所以这就是我正在做的事情。 这是一个可重现的例子 a = c("ab", "ba", "ca") b = c("ab", "dd", "da") c = c("cd", "fa", "op") data = data.frame(a,b,c, row.names = c("row1", "row2", "row3") colnames(data) <- c("col1", "col2", "col3") data[,"col1
I have an Excel workbook of which I want to edit/fill some particular cells using R, without changing any of the formatting. So far I've tried XLConnect package and it seems it could do what I'm looking for, I just didn't find a way to do it. My straightforward approach to the problem: wb <- loadWorkbook("file1.xls") data1 <- readWorksheet(wb, "Sheet1", header=TRUE) ## add
我有一个Excel工作簿,我想用R编辑/填充一些特定的单元格,而不更改任何格式。 到目前为止,我已经尝试过XLConnect包,它似乎可以做我正在寻找的东西,我只是没有找到办法做到这一点。 我对问题的直截了当的方法: wb <- loadWorkbook("file1.xls") data1 <- readWorksheet(wb, "Sheet1", header=TRUE) ## adding a value to a particular cell: data1[11,12] <- 3.2 ## rewriting old data: writeWorksheet(wb,