在ggplot2中,如何阻止轴标签缩写 - 例如1e+00, 1e+01,一旦绘制了x轴?理想情况下,我想强制R显示在这种情况下的实际值1,10.
任何帮助非常感谢.
我正在使用Rmarkdown在gh-pages上建立一个网站.但是,在R studio中,您只能创建新的.Rmd文件.这是一个问题,因为在推送到我的github repo之前,我需要将.Rmd文件转换为.md文件.
有没有人有一些建议?
提前致谢!
使用标准R图形将线性模型趋势线添加到箱线图时,我使用:
boxplot(iris[,2]~iris[,1],col="LightBlue",main="Quartile1 (Rare)")
modelQ1<-lm(iris[,2]~iris[,1])
abline(modelQ1,lwd=2)
Run Code Online (Sandbox Code Playgroud)
但是,在ggplot2中使用它时:
a <- ggplot(iris,aes(factor(iris[,1]),iris[,2]))
a + geom_boxplot() +
geom_smooth(method = "lm", se=FALSE, color="black", formula=iris[,2]~iris[,1])
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
geom_smooth: Only one unique x value each group.Maybe you want aes(group = 1)?
Run Code Online (Sandbox Code Playgroud)
这条线没有出现在我的情节中.
这两种情况中使用的模型是相同的.如果有人能指出我哪里出错了,那就太好了.
编辑:使用虹膜数据集作为示例.
我想这会有一个简单的答案,但我无法解决它!以下是使用iris数据集的示例:
a <- table(iris[,2])
b <- table(iris[,3])
Run Code Online (Sandbox Code Playgroud)
如何将这两个表一起添加?例如,变量3在新输出表中的值为27(26 + 1),变量3.3的值为8(6 + 2).
任何帮助非常感谢.
当我使用此代码时,标准R绘图在一个图中产生30个箱图:
boxplot(Abundance[Quartile==1]~Year[Quartile==1],col="LightBlue",main="Quartile1 (Rare)")
Run Code Online (Sandbox Code Playgroud)
我想在ggplot2中生成类似的东西.到目前为止我正在使用这个:
d1 = data.frame(x=data$Year[Quartile==1],y=data$Abundance[Quartile==1])
a <- ggplot(d1,aes(x,y))
a + geom_boxplot()
Run Code Online (Sandbox Code Playgroud)
有30年的数据.每年有145种.在每年,145种物种被分为1-4的四分位数.
但是,我只使用它来获得一个盒子图.知道如何沿x轴获得30个箱图(每年一个)吗?任何帮助非常感谢.
有30年的数据.每年有145种.在每年,145种物种被分为1-4的四分位数.
我正在尝试使用ggplot2绘制具有2组数据的直方图.我的数据集有418个要绘制的值,有2组数据(因此我的直方图上会有2组彩色条).令人讨厌的是我无法用iris数据集重现问题:
library(ggplot2)
ggplot(iris, aes(x=iris[,1], fill=iris[,5])) +
geom_histogram(binwidth=.5,alpha=.5)
Run Code Online (Sandbox Code Playgroud)
这样可以创建直方图.当我在我的数据上尝试时,我得到:
Error : cannot allocate vector of size 4.0 Gb
In addition: Warning messages:
1: In anyDuplicated.default(breaks) :
Reached total allocation of 16366Mb: see help(memory.size)
2: In anyDuplicated.default(breaks) :
Reached total allocation of 16366Mb: see help(memory.size)
3: In anyDuplicated.default(breaks) :
Reached total allocation of 16366Mb: see help(memory.size)
4: In anyDuplicated.default(breaks) :
Reached total allocation of 16366Mb: see help(memory.size)
Error in UseMethod("scale_dimension") :
no applicable method for 'scale_dimension' applied to an object …Run Code Online (Sandbox Code Playgroud) 我已经浏览了这个网站上现有的Q&A子集,但是找不到我想要的东西.
我想基于一个条件对数据帧进行子集化(例如,如果该值低于5).但是,我只想要所有列中的值低于5的行.
例如,使用iris数据集 - 我想选择列1-3都具有低于5的值的所有行.
subdata <- iris[which(iris[,1:3]<5),]
Run Code Online (Sandbox Code Playgroud)
这不适合我.我在子集数据的底部得到了很多NA行.
任何帮助非常感谢!
我正在使用以下示例:
Original Modified New_Orig New
1 2 1 0
2 4 1 0
3 6 4 0
4 8 5 0
5 10 5 0
6 12 5 0
7 14 5 0
8 16 5 0
9 18 9 0
10 20 10 0
Run Code Online (Sandbox Code Playgroud)
我希望New用Modifiedif New_Orig中的任何值替换值中的值Original.
理想情况下New看起来像这样:
New
2
2
8
10
10
10
10
10
18
20
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢.
亲切的问候,