更改 ggplot 凹凸图上的文本大小

发布于 2024-09-05 18:55:24 字数 936 浏览 0 评论 0原文

我对 ggplot 还很陌生。我使用下面发布的代码制作了一个凹凸图。我从某人的博客获得了代码 - 我丢失了链接...

我希望能够增加标签的大小(这里的字母在图的左侧和右侧非常小)而不影响宽度行的数量(这只有在运行代码后才真正有意义)

我尝试过更改大小参数,但这总是会改变行的宽度。

任何建议表示赞赏。

汤姆

require(ggplot2)
df<-matrix(rnorm(520), 5, 10) #makes a random example
colnames(df) <- letters[1:10] 
Price.Rank<-t(apply(df, 1, rank))
dfm<-melt(Price.Rank)
names(dfm)<-c( "Date","Brand", "value")
p <- ggplot(dfm, aes(factor(Date), value,
 group = Brand, colour = Brand, label = Brand))
p1 <- p + geom_line(aes(size=2.2, alpha=0.7)) + 
    geom_text(data = subset(dfm, Date == 1), aes(x = Date , size =2.2, hjust =      1, vjust=0)) + 
    geom_text(data = subset(dfm, Date == 5), aes(x = Date , size =2.2, hjust =  0, vjust=0))+
    theme_bw() + 
    opts(legend.position = "none",  panel.border = theme_blank()) 

p1 + theme_bw() + opts(legend.position = "none",  panel.border = theme_blank())

I'm fairly new to ggplot. I have made a bumpplot using code posted below. I got the code from someones blog - i've lost the link....

I want to be able to increase the size of the lables (here letters which care very small on the left and right of the plot) without affecting the width of the lines (this will only really make sense after you have run the code)

I have tried changing the size paramater but that always alter the line width as well.

Any suggestion appreciated.

Tom

require(ggplot2)
df<-matrix(rnorm(520), 5, 10) #makes a random example
colnames(df) <- letters[1:10] 
Price.Rank<-t(apply(df, 1, rank))
dfm<-melt(Price.Rank)
names(dfm)<-c( "Date","Brand", "value")
p <- ggplot(dfm, aes(factor(Date), value,
 group = Brand, colour = Brand, label = Brand))
p1 <- p + geom_line(aes(size=2.2, alpha=0.7)) + 
    geom_text(data = subset(dfm, Date == 1), aes(x = Date , size =2.2, hjust =      1, vjust=0)) + 
    geom_text(data = subset(dfm, Date == 5), aes(x = Date , size =2.2, hjust =  0, vjust=0))+
    theme_bw() + 
    opts(legend.position = "none",  panel.border = theme_blank()) 

p1 + theme_bw() + opts(legend.position = "none",  panel.border = theme_blank())

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-09-12 18:55:24

试试这个

  geom_text(data=subset(dfm, Date == 1), aes(x=Date),
            size=12, hjust=1, vjust=0) +
  geom_text(data=subset(dfm, Date == 5), aes(x=Date),
            size=20, hjust=0, vjust=0)

,即将大小设置在 aes 映射之外。

Try this

  geom_text(data=subset(dfm, Date == 1), aes(x=Date),
            size=12, hjust=1, vjust=0) +
  geom_text(data=subset(dfm, Date == 5), aes(x=Date),
            size=20, hjust=0, vjust=0)

i.e., set the size outside of the aes mapping.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文