Reputation: 18239
General Goal
I am placing guests around tables according to a set of rules. My goal, in this post, is to have a handy function to display the names of these guests around their respective tables on a R
graphic.
Input Data
guests
describes the position of each guest at each table. Note that the number of guests per table varies.
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
indicate where each table should be positioned on the graph. I assume here that each axis goes from 0 to 10, where the point c(5,5)
is at the center of the graph.
Table_positions = data.frame(
y_position=c(3,2,3,7,8,7),
x_position=c(3,5,7,3,5,7)
)
Details of the graphic
I suggest that the tables are represented by circles centered at the position indicated by the data.frame Table_positions
. The names of each guest should be written around these tables following the list guests
.
Upvotes: 0
Views: 68
Reputation: 1089
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)
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)
}
}
I added table4 with one pepole named "Bla".
You can specify the text size with cex
option (here 0.5).
Upvotes: 4