【问题标题】:X axis labels cut off in Jupyter with R在 Jupyter 中用 R 截断 X 轴标签
【发布时间】:2017-04-13 15:23:16
【问题描述】:

我和How can I make my vertical labels fit within my plotting window? 的人有同样的问题,但在 Jupyter。当我在 Jupyter 中的 R 中制作条形图时,任何长的垂直 x 轴标签都会被切断。例如

animals = c("dog","cat","squirrel","dog","fox","dog","llama","cat","tyrannosaurus rex")
sorted <- sort(table(animals), decreasing=T)
barplot(sorted, las = 2)

使用链接问题的解决方案

animals = c("dog","cat","squirrel","dog","fox","dog","llama","cat","tyrannosaurus rex")
sorted <- sort(table(animals), decreasing=T)
par(mar = c(15,4,4,2) + 0.1) 
barplot(sorted, las = 2)

适用于 Mac 的 R gui,但不适用于 Jupyter。

例如,我也尝试过使用 repr 及其选项

library(repr)
options(repr.plot.width=4, repr.plot.height=4)

虽然这可以缩小和拉伸情节,但底部仍然会被切断。

有什么想法吗?

【问题讨论】:

    标签: r plot jupyter


    【解决方案1】:

    好吧,经过大量搜索,仍然无法正确找到它。我能够让它与 ggplot 一起工作

    library(ggplot2)
    animals = c("dog","cat","squirrel","dog","fox","dog","llama","cat","tyrannosaurus rex")
    bars<- ggplot()+
        aes(x=animals)+
        geom_bar(stat="count")+
        theme(axis.text.x = element_text(angle = 90, hjust = 1))
    print(bars)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多