ggplot:在plot之外添加多行文本注释

时间:2017-09-24 23:17:54

标签: r ggplot2 textbox

我想在ggplot的情节区域外添加10个单独的堆叠线条的文本框。我的文字是t = c("a=1", "b=2", "c=3", ... , "j=10"),但这些标签与我制作原始data.frame的{​​{1}}无关。如何在绘图区域外添加10行?

例如,我想在下图右侧的向量ggplot周围添加一个文本框:

t

2 个答案:

答案 0 :(得分:4)

尝试

def main():
    total = 0
    print('Welcome to the Dew Drop Inn!')
    print('Please enter your choices as y or n.')
    print('     ')
    cheese = (input('Do you want a grilled cheese? '))
    dog = (input('Do you want a hot dog? ')) 
    nacho = (input('Do you want nachos? '))
    burger = (input('Do you want a hamburger? '))
    grilled_cheese = 5
    hot_dog = 5
    nachos = 4
    hamburger = 6
    cheese_burger = 1
    if cheese == 'y':
        total + grilled_cheese
    if dog == 'y':
        total + hot_dog
    if nacho == 'y':
        total + nachos
    if burger == 'y':
        total + hamburger
        the_cheese_please = input('Do you want cheese on that? ')
        if the_cheese_please == 'y':
            total + cheese_burger
    else:
        total + 0

    print('     ')
    print('The total for your food is $',(total),'.')
    tip = total * 1.15


main()

答案 1 :(得分:2)

您可以使用library(gridExtra) grid.arrange(p, right = tableGrob(matrix(t,ncol=1), theme = ttheme_minimal(padding = unit(c(3,1),"line")))) 中的标签值创建geom_text图层,以便将标签打印为图例。但我们在t中设置alpha=0,以便这些标签不会包含在图中,我们会使用geom_textlegend.key=element_blank()来获取“图例”标签( override.aes(list(size=0))值)打印时没有无意义的图例键。

t

enter image description here