我看到已经提出这样的问题......,解决加stat = "identity"来geom_bar.但就我而言,这并没有解决任何问题(我仍然得到消息"情节中没有图层").
我得到了一个简单的data.frame(data3),包含2个因子(MonthNB和StationNAME)和一个数值变量(Ptot):
MonthNB StationNAME Ptot
1 stationA 21.70625
2 stationA 16.19375
3 stationA 16.64688
4 stationA 27.37813
5 stationA 38.26774
6 stationA 52.91250
7 stationA 69.36875
8 stationA 43.18125
9 stationA 33.24688
10 stationA 35.74839
11 stationA 36.01333
12 stationA 30.24194
1 stationB 25.14242
2 stationB 18.62121
3 stationB 22.11818
4 stationB 32.70909
5 stationB 33.83750
6 stationB 63.65937
7 stationB 69.05312
8 stationB 50.70606
9 stationB 46.96364
10 stationB 50.28710
11 stationB 46.81935 …Run Code Online (Sandbox Code Playgroud) 有没有人知道如何用ggplot2旋转日期格式的轴刻度?我希望获得带有"Date-Month"(例如"1985-5")的标签,x轴上的角度为45°.
数据样本:
Station Date Ptot
A 1980-02 16
A 1980-03 19
A 1980-04 40
A 1980-05 48
A 1980-06 NA
A 1980-07 18.5
A 1980-08 24.6
B 1980-07 50.8
B 1980-08 28.9
B 1980-09 32.9
B 1980-10 47.9
B 1980-11 16.3
Run Code Online (Sandbox Code Playgroud)
我试过这个:
library(ggplot2)
library(scales)
plot <- ggplot(data=na.omit(data), aes(x=Date, y=Ptot, group=Station))+
geom_line()+
facet_grid(Station~.)+
scale_x_date(breaks = "year", labels=date_format("%Y-%m"))+
xlab("Year")+
ylab("Prec (mm)")+
labs(colour = "Station")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
theme_bw()
plot
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
谢谢!
使用R,我想组合成两个不同列中包含的月份nb(月份)和nb(day)的一列(日期),并以日期格式使用创建的列.
我的数据框看起来像这样:
St Dep Month Day
A 2 1 1
B 2 1 1
B 2 2 1
A 5 1 1
A 7 1 1
C 2 1 1
C 5 1 1
Run Code Online (Sandbox Code Playgroud)
我想添加一个类似"Jan-01"的列.
我的数据集如下所示(我们称之为“a”):
date value
2013-01-01 12.2
2013-01-02 NA
2013-01-03 NA
2013-01-04 16.8
2013-01-05 10.1
2013-01-06 NA
2013-01-07 12.0
Run Code Online (Sandbox Code Playgroud)
我想NA用最接近的环境值(该系列中的上一个和下一个值)的平均值来替换 。
我尝试了以下操作,但我对输出不满意......
miss.val = which(is.na(a$value))
library(zoo)
z = zoo(a$value, a$date)
z.corr = na.approx(z)
z.corr[(miss.val - 1):(miss.val + 1), ]
Run Code Online (Sandbox Code Playgroud) 让我们考虑以下示例:
library(ggplot2)
zzz <- data.frame(gp = c("a","b","c","d","e","f","g","h","i","j","k","l","m"),
c1 = c(1,1,1,1,1,1,1,1,1,1,1,1,1),
c2 = c(1,1,1,1,1,1,1,1,1,1,1,1,1))
ggplot(zzz, aes(x = c1, y = c2)) +
facet_wrap(~ gp, scales = "free", strip.position = "bottom") +
geom_point() +
theme(
aspect.ratio = 1,
strip.background = element_blank(),
strip.placement = "outside"
)
Run Code Online (Sandbox Code Playgroud)
为什么我会收到以下错误?我怎么能克服它?
Error in vapply(row_axes, is.zero, logical(length(row_axes))) :
values must be length 3,
but FUN(X[[1]]) result is length 1
Run Code Online (Sandbox Code Playgroud)
我测试的一些调整显示,如果出现以下情况则没有问题:
a)我在data.frame中删除了一行,或者如果我再添加2行,每行包含一个新组,或者
b)我删除strip.placement = "outside"或strip.position = "bottom"
那是一个错误吗?我错过了什么?我想保持条纹设置的美学......
我有以下宽数据框(mydf.wide):
DAY JAN F1 FEB F2 MAR F3 APR F4 MAY F5 JUN F6 JUL F7 AUG F8 SEP F9 OCT F10 NOV F11 DEC F12
1 169 0 296 0 1095 0 599 0 1361 0 1746 0 2411 0 2516 0 1614 0 908 0 488 0 209 0
2 193 0 554 0 1085 0 1820 0 1723 0 2787 0 2548 0 1402 0 1633 0 897 0 411 0 250 0
3 246 0 533 …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个 pandoc lua 过滤器来替换乳胶包 mhchem 中的 \ce{} 命令。
这是我在 的示例中尝试的\ce{NO3-},但它不起作用并在 rtf 输出文件中呈现空白:
return {
{
Str = function (elem)
if elem.text == "\\ce%{%NO3-%}%" then
return {pandoc.Str "NO3"}
else
return elem
end
end,
}
}
Run Code Online (Sandbox Code Playgroud)
我的 pandoc 命令是:
pandoc -s myfile.tex --lua-filter myfilter.lua -o myfile.rtf
Run Code Online (Sandbox Code Playgroud) R不会自动绘制英文轴标签(例如,月份是法语).我使用(如果信息有用......):
我知道我不是唯一有这个问题的人,但我从来没有找到解决方案.
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C LC_TIME=French_France.1252
Run Code Online (Sandbox Code Playgroud) 我在内存中有许多 data.tables,其名称遵循特定的模式(例如:RE_1、RE_2...CO_1、CO_2...)。我想有效地绑定它们以获得两个 data.tables(RE 和 CO)。
我试过:
RE <- rbindlist(ls(pattern = "RE"))
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:“rbindlist(ls(pattern = "RE")) 中的错误:rbindlist 的输入必须是 data.tables 列表”。
有没有办法制作这样一个“可用”的 data.tables (或数据框)列表?
我有一个数据框(df)具有以下结构:
ID TIME VAR1 VAR2
truc 4 2 30
truc 10 4 60
truc 40 6 90
bidule 4 5 12
bidule 10 15 13
bidule 40 45 14
Run Code Online (Sandbox Code Playgroud)
我想使用操纵来选择要绘制的变量(VAR1或VAR2).这是我尝试过的:
manipulate(
ggplot(df, aes(x=TIME, y=y.factor, color=ID))+
geom_point(),
y.factor=picker(VAR1, VAR2)
)
Run Code Online (Sandbox Code Playgroud)