如何在R中创建stem图?

如何在R中创建stem图?,r,matlab,stem,R,Matlab,Stem,我想在R中创建一个干图。我有一个matlab代码,但不知道如何在R中编写相同的代码。matlab代码如下 x = 0:25; y = [exp(-.07*x).*cos(x);exp(.05*x).*cos(x)]'; h = stem(x,y); set(h(1),'MarkerFaceColor','blue') set(h(2),'MarkerFaceColor','red','Marker','square') h(1) is the handle to the stemseries

我想在R中创建一个干图。我有一个matlab代码,但不知道如何在R中编写相同的代码。matlab代码如下

x = 0:25;
y = [exp(-.07*x).*cos(x);exp(.05*x).*cos(x)]';
h = stem(x,y);
set(h(1),'MarkerFaceColor','blue')
set(h(2),'MarkerFaceColor','red','Marker','square')

h(1) is the handle to the stemseries object plotting the expression exp(-.07*x).*cos(x).
h(2) is the handle to the stemseries object plotting the expression exp(.05*x).*cos(x).

下面是代码的起点

x <- 0:25
y <- cbind(exp(-.07*x)*cos(x), exp(.05*x)*cos(x))

df <-  data.frame(y=c(exp(.05*x)*cos(x),exp(-.07*x)*cos(x)),
   x=rep(x,2), grp=factor(rep(c(1,2),each=length(x))))

library(ggplot2)
p <- ggplot(aes(group=grp, col=grp, shape=grp), data=df) + 
    geom_hline(aes(yintercept=0)) +
    geom_segment(aes(x,y,xend=x,yend=y-y)) + 
    geom_point(aes(x,y),size=3) 
p

x这里是代码的起点

x <- 0:25
y <- cbind(exp(-.07*x)*cos(x), exp(.05*x)*cos(x))

df <-  data.frame(y=c(exp(.05*x)*cos(x),exp(-.07*x)*cos(x)),
   x=rep(x,2), grp=factor(rep(c(1,2),each=length(x))))

library(ggplot2)
p <- ggplot(aes(group=grp, col=grp, shape=grp), data=df) + 
    geom_hline(aes(yintercept=0)) +
    geom_segment(aes(x,y,xend=x,yend=y-y)) + 
    geom_point(aes(x,y),size=3) 
p

x你在谷歌上搜索过吗?堆栈溢出不是代码转换服务。你应该在一个文档中包含数据,并更精确地描述所需的输出(链接到一个示例图片会很有帮助)。但是,我有两个组(A和B),我想绘制一段时间内的铅含量(y轴)(x轴-例如0、1、2、3),你用谷歌搜索过吗?堆栈溢出不是代码转换服务。你应该在一个文档中包含数据,并更精确地描述所需的输出(链接到一个示例图片会很有帮助)。但是,我有两个组(A和B),我想绘制一段时间内的铅含量(y轴)(x轴-例如0、1、2、3)