我创建了一个散点图(多组GRP)用IV=time,DV=concentration.我想在(0.025,0.05,0.5,0.95,0.975)我的情节中添加分位数回归曲线.
顺便说一句,这就是我创建散点图的方法:
attach(E) ## E is the name I gave to my data
## Change Group to factor so that may work with levels in the legend
Group<-as.character(Group)
Group<-as.factor(Group)
## Make the colored scatter-plot
mycolors = c('red','orange','green','cornflowerblue')
plot(Time,Concentration,main="Template",xlab="Time",ylab="Concentration",pch=18,col=mycolors[Group])
## This also works identically
## with(E,plot(Time,Concentration,col=mycolors[Group],main="Template",xlab="Time",ylab="Concentration",pch=18))
## Use identify to identify each point by group number (to check)
## identify(Time,Concentration,col=mycolors[Group],labels=Group)
## Press Esc or press Stop to stop identify function
## Create legend
## Use …Run Code Online (Sandbox Code Playgroud) 我有这个数据,我给它命名为A:
A <- read.table(text = "ID TIME EVID AMT DOSE
1 10 1 100 20
1 12 1 100 20
1 14 1 100 20
1 16 1 100 20
1 17 0 100 20
1 18 1 100 20
1 20 1 100 20
1 22 1 100 20
2 5 1 100 40
2 10 1 100 40
2 15 1 100 40
2 17 0 100 40
2 20 1 100 40
3 4 1 100 25 …Run Code Online (Sandbox Code Playgroud) 我昨天刚开始玩ggplot.具有负值的条形图的代码按我的预期工作:
dtf1 <- data.frame(ID = c(1:10),Diff = c(-5:4))
dtf1$colour <- ifelse(dtf1$Diff < 0, "firebrick1","steelblue")
dtf1$hjust <- ifelse(dtf1$Diff > 0, 1.3, -0.3)
ggplot(dtf1,aes(ID,Diff,label="",hjust=hjust))+
geom_text(aes(y=0,colour=colour))+
geom_bar(stat="identity",position="identity",aes(fill = colour))
Run Code Online (Sandbox Code Playgroud)
但是,当我将相同的代码应用于仅具有正值的其他数据集时,情况并非如此
dtf <- data.frame(ID = c(1:10),Diff = rnorm(10,3))
dtf$colour <- ifelse(dtf$Diff < 0, "firebrick1","steelblue")
dtf$hjust <- ifelse(dtf$Diff > 0, 1.3, -0.3)
ggplot(dtf,aes(ID,Diff,label="",hjust=hjust))+
geom_text(aes(y=0,colour=colour))+
geom_bar(stat="identity",position="identity",aes(fill = colour))
Run Code Online (Sandbox Code Playgroud)

我发现我可以调整代码的最后一行,为我的正条形图获得蓝色,
geom_bar(stat="identity",position="identity",fill="steelblue")
因此,我的两个问题是:

看起来颜色可能更接近绿松石3而不是钢蓝.
我一定是在问一个非常简单的问题.我不知道如何最好地表达它,因此很难找到解决方案.如果问题已被提出,我很抱歉,我很乐意删除自己.
我正在尝试按 ID 合并两个不同大小的数据。但是,对于匹配的值,两个数据都包含重复条目,即数据A中可能有三个ID#3,数据B中可能有三个ID#3。当我尝试合并数据时,结果比两者都大数据结合。
C<-merge(A,B,by="ID",all.x=T,sort=F)
我想通过 ID 列合并两个数据,以便 B 中的第一个 ID #3 与 A 中的第一个 ID #3 配对,依此类推。
另外,我希望数据 A 的行顺序保持不变。sort=FALSE 没有太大帮助:它将所有匹配的行放在顶部,将不匹配的行放在底部。
谢谢你的帮助!
我在R中有这个,我希望将每个ID号彼此相邻,然后按日期排序,最后按时间排序......这可能吗?
ID Val Date Time
1 1 0.7 1/13/2013 12:00
2 2 1.6 1/13/2013 12:00
3 3 0.5 1/13/2013 12:00
4 4 2.1 1/13/2013 12:00
5 5 1.2 1/13/2013 12:00
6 1 1.0 1/13/2013 13:00
7 2 1.1 1/13/2013 13:00
8 3 0.9 1/13/2013 13:00
9 4 2.4 1/13/2013 13:00
10 5 0.8 1/13/2013 13:00
Run Code Online (Sandbox Code Playgroud) r ×5
colors ×1
date ×1
duplicates ×1
ggplot2 ×1
insert ×1
merge ×1
quantile ×1
regression ×1
row ×1
scatter-plot ×1
sorting ×1
time ×1