运用 df
date <- c(rep(as.Date("2003-01-05"), 5), rep(as.Date("2004-01-05"), 5), rep(as.Date("2005-01-05"), 5), rep(as.Date("2006-01-05"), 5))
parameter <- rep(c("param_A", "param_B", "param_C", "param_D", "param_E"), 4)
df <- data.frame(date, parameter)
df$year <- year(df$date)
Run Code Online (Sandbox Code Playgroud)
我怎样才能删除param_A,2003但保留所有其他年份?
我有这个数字
以下是类似问题的答案
library(ggplot2)
library(egg)
mydf <- transform(mydf, variables = reorder(variables, VIP, decreasing = T))
p1 <-
ggplot(mydf, aes(x = variables, y = VIP, group =1))+
geom_bar(stat="identity") +
geom_hline(yintercept = 1, size = 2, linetype = 3) +
theme(axis.title.x =element_blank())
p2 <-
ggplot(mydf, aes(x = variables, y = coefficient, group =1))+
geom_point()+
geom_line()+
geom_hline(yintercept = 0, size = 2, linetype = 3)
grid.draw(egg::ggarrange(p1,p2 , ncol=1))
Run Code Online (Sandbox Code Playgroud)
我的目标是从最高到最低订购酒吧.
虽然,我variables and VIP从最高到最低排序,酒吧从最低到最高排序.
知道出了什么问题,并使条形从最低到最高排序?
数据
mydf <- read.table(text = c("
variables …Run Code Online (Sandbox Code Playgroud) 使用此data.frame
数据
df <- read.table(text = c("
SiteID measured modelled
site1 50 47
site2 28 30
site3 158 162
site4 247 243
site5 456 463
site6 573 564
site7 634 640"), ,header =T)
Run Code Online (Sandbox Code Playgroud)
我想创建两个新列(measured_diff和modelled_diff).在这两个新列中,site1和site2的值将与测量和建模的值相同.但是,对于其他站点,其值将类似于以下
site3的measured_diff = site3的测量 - 总和(测量site1和site2)
site4的measured_diff = site4的测量值 - 测量site3
site5的measured_diff = site5的测量值 - site4的测量值
site6的measured_diff = site6的测量值 - site5的测量值
site7的measured_diff = site7的测量值 - 为site6测量
同样的 modelled_diff
最后结果
它应该如下
# SiteID measured modelled diff_measured diff_modelled
#1 site1 50 47 50 47
#2 site2 28 30 28 …Run Code Online (Sandbox Code Playgroud) 我使用下面的数据和代码得到了这个图
我希望能够更改图例文本的大小(A,B,M1,M3)。我尝试使用
legend.text=element_text(size=0.5)
Run Code Online (Sandbox Code Playgroud)
但它并没有改变。有什么建议如何减少legend.text的大小?
码
ggplot(df.trial1, aes(x=Date, y= A, color="A"))+
geom_line(linetype=3, size=0.2)+
geom_point(aes(x=Date, y=B, color="B"), shape = 16, size =1, alpha=0.5)+
geom_point(aes(x=Date, y=Value, color=Method), size =1, alpha=0.5)+
scale_colour_manual(name=" ", values=cols,
labels=c("A", "B", 'M1', "M2", "M3"))+
scale_linetype_manual(values = c("dashed")) +
scale_x_date(breaks = date_breaks("1 month"), labels = date_format("%d-%b-%y"))+
guides(color=guide_legend(override.aes=list(shape=c(NA,16, 16, 16, 16),
linetype=c(3,0, 0, 0, 0)),
direction = "vertical", title.position = "top",
label.position="right", label.hjust = 0, label.vjust = 0.5,
label.theme = element_text(angle = 0)))+
labs(x=expression(Date), y=expression(Value))+
theme(legend.text=element_text(size=0.5))
Run Code Online (Sandbox Code Playgroud) 在此shapefile中,几何列是线串,除了 4 个流到达 ( 8168547, 8171738, 8170616 ,8169920) 是多线串之外。
我需要将每个多线串仅转换为一个线串。我尝试了很多方法但没有成功。例如,我st_cast在 R 中尝试了 sf 包。但是,它增加了行数(它将每个多线串转换为多个线串)。
如何将每个多线串仅转换为一个线串?