楼主: peijianshi
6335 19

[问答] R中上标的一个问题 [推广有奖]

11
UNC 发表于 2011-11-6 02:56:57
shenbaiseshatan 发表于 2011-11-4 16:27
1.这个问题属于tex的基本语法
2.如果输出的文字超出图形范围,可以更改文字输出的位置
tex的基本语法?

12
ywh19860616 发表于 2013-3-13 15:56:41
这个上标在R中如何画出来的?

未命名.jpg (8.78 KB)

未命名.jpg

一份耕耘,一份收获。

13
zhangyangsmith 发表于 2013-3-13 17:09:13
Try:
  1. expression(X[1]^(2))
复制代码

14
ywh19860616 发表于 2013-3-13 18:31:14
zhangyangsmith 发表于 2013-3-13 17:09
Try:
您好,好像做不出像12楼的效果图,以下是一个代码
x=c(1,1,2,2,1,1,2)
y=c(1,2,2,5,5,3,3)
plot(x,y,main="X vs Y", xlab="X", ylab="Y")
lines(x,y,col="black",lty="dotted")
a=c('x^(1)','x2','x3','x4','x5','x6','x7')
b=c('y1','y2','y3','y4','y5','y6','y7')
text(x,y,labels=paste("(",a,",",b,")"),pos=1,cex=0.7)
一份耕耘,一份收获。

15
zhangyangsmith 发表于 2013-3-13 21:01:24
  1. # Define x and y as appropriate
  2. plot(x,y,main="X vs Y", xlab="X", ylab="Y", xlim = c(1, 2.2), ylim = c(0, 6))
  3. lines(x,y,col="black",lty="dotted")
  4. sapply(1:length(x), function(i) text(x[i], y[i], labels = bquote(paste("(", X[1]^(.(i)), ", ", X[2]^(.(i)), ")", sep = "")), adj = c(0, 0)))
复制代码

superscriptText.png

Is this what you expect?
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 5 + 5 + 5 Thanks for your help

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

16
ywh19860616 发表于 2013-3-14 08:16:56
zhangyangsmith 发表于 2013-3-13 21:01
Is this what you expect?
Thanks
谢谢您的答复
这个图效果很好,我想请教下,有没有办法修改为更普遍的,
意思就是如12楼的图例,上标不一定都是同一个数字的,
您能就几个点举个例子吗?或许这个不能用循环,但是只要能
达到目的即可。
一份耕耘,一份收获。

17
zhangyangsmith 发表于 2013-3-14 15:53:56
  1. # Assign x and y as above
  2. itr <- data.frame(x = c(1, rep(2:((length(x) + 1)/2), each = 2)), y = c(rep(1:((length(y) + 1)/2 - 1), each = 2), (length(y) + 1)/2))
  3. plot(x,y,main="X vs Y", xlab="X", ylab="Y", xlim = c(1, 2.2), ylim = c(0, 6))
  4. lines(x,y,col="black",lty="dotted")
  5. sapply(1:length(x), function(i) text(x[i], y[i], labels = bquote(paste("(", X[1]^(.(itr$x[i])), ", ", X[2]^(.(itr$y[i])), ")", sep = "")), adj = c(0, 0)))
复制代码

superscriptTextGibbs.png

If you are about to write a book about Bayesian stats I'm gonna ask for a free copy ...
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 5 + 5 + 5 Good job,thanks

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

18
ywh19860616 发表于 2013-3-14 16:14:51
zhangyangsmith 发表于 2013-3-14 15:53
If you are about to write a book about Bayesian stats I'm gonna ask for a free copy ...{:soso_ ...
哈哈,谢谢zhangyangsmith
Perfect

可是还需要对这个图形进行修改一下,比如
第一点的上下坐标都是(1) 、(1),
第二点的横坐标没有改变,只是纵坐标改变,所以我期望
上标为(1)、(2)。
同样,第三点的横坐标改变了,纵坐标没有改变,所以为(2)、(2)
其他同理。

ps:其实可以针对具体情况修改您程序中的itr数据框,哈哈。
只是能直接表达更好。
还有,我最后两点取的不妥。删除了一个点。

x=c(1,1,2,2,1,1)
y=c(1,2,2,5,5,3)
# Assign x and y as above
itr <- data.frame(x=c(1,1,2,2,3,3),y=c(1,2,2,3,3,4))
plot(x,y,main="X vs Y", xlab="X", ylab="Y", xlim = c(1, 2.2), ylim = c(0, 6))
lines(x,y,col="black",lty="dotted")
sapply(1:length(x), function(i) text(x, y, labels = bquote(paste("(", X[1]^(.(itr$x)), ", ", X[2]^(.(itr$y)), ")", sep = "")), adj = c(0, 0)))


itr可以直接如您开始写的用公式表示吗。
一份耕耘,一份收获。

19
zhangyangsmith 发表于 2013-3-14 16:57:26
ywh19860616 发表于 2013-3-14 16:14
哈哈,谢谢zhangyangsmith
Perfect
ps:其实可以针对具体情况修改您程序中的itr数据框,哈哈。
Agree
还有,我最后两点取的不妥。删除了一个点。
I am not sure if you want to delete one point and plot the status in the middle of one iteration, i.e. y has been updated but not x.
itr可以直接如您开始写的用公式表示吗。
Not quite understand. But the bquote function returns an expression but with substitution of the variable that was in the .() with its values. If you use expression it will just show i instead of 1, 2, ...
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 Thanks

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

20
ywh19860616 发表于 2013-3-14 20:58:26
zhangyangsmith 发表于 2013-3-14 16:57
Agree

I am not sure if you want to delete one point and plot the status in the middle of one  ...
Thanks
理解您说的了,非常谢谢
一份耕耘,一份收获。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 07:12