2016-06-28 62 views
0

總體目標R:作圖表計劃

我根據一組規則放置客人在桌附近。在這篇文章中,我的目標是擁有一個方便的功能,可以在R圖形上顯示這些客人的名字。

輸入數據

guests描述了每個客人的在每個表中的位置。請注意,每張桌子的客人人數各不相同。

guests = list(
    table_1 = c("Jack", "Christelle", "Frank", "John S.", "Lucia"), 
    table_2 = c("George", "Amanda", "Alice", "Laura", "John H."), 
    table_3 = c("Jeanette", "Elizabeth", "Remi", "Fabian", "Urs", "Emma"), 
    table_5 = c("Roger", "Marry", "Henrique", "Claire", "Julia"), 
    table_6 = c("Alphonse", "Marie", "Dani", "Rachel") 
) 

Table_positions指示每個表應放置在圖上的位置。我在這裏假定每個軸從0到10,其中點c(5,5)位於圖的中心。的圖形

Table_positions = data.frame(
    y_position=c(3,2,3,7,8,7), 
    x_position=c(3,5,7,3,5,7) 
) 

詳細我建議表由在由data.frame Table_positions指示的位置爲中心的圓圈表示。每個訪客的姓名應該在列表guests的後面寫在這些表格的周圍。

+0

你想通過表或所有表在同一圖中繪製表格嗎? –

+0

我想你必須玩'plotrix :: draw.circle' –

+0

@ChristopheD。所有表格(和所有名稱)在一張圖上。它允許有一個房間的代表。這是一個桌面計劃 –

回答

4

放置表:

require(plotrix) 
plot(x = Table_positions$x_position 
    ,y= Table_positions$y_position 
    ,xlim=c(0,10),ylim=c(0,10),pch=".") 
draw.circle(Table_positions$x_position, 
     radius=0.5, 
     Table_positions$y_position) 

enter image description here

客人定位:

for(i in 1:length(guests)){ 
    Table<-as.vector(unlist(guests[i])) 
    posTable<-c(Table_positions$x_position[i],Table_positions$y_position[i]) 
    nbGuest<-length(Table) 
    for(j in 1:nbGuest){ 
    text(x=posTable[1]+round(0.5*cos((2*j/nbGuest)*pi),2), 
     y=posTable[2]+round(0.5*sin((2*j/nbGuest)*pi),2), 
     labels=guests[[i]][[j]], 
     cex=0.5) 
    } 

} 

enter image description here

我添加表4與名爲 「布拉」 一個生民。
您可以使用cex選項(此處爲0.5)指定文本大小。