В разделе 8.4 из книга объясняет, как это сделать. Хитрость заключается в использовании пакета grid
пакета viewport
s.
#Any old plot
a_plot <- ggplot(cars, aes(speed, dist)) + geom_line()
#A viewport taking up a fraction of the plot area
vp <- viewport(width = 0.4, height = 0.4, x = 0.8, y = 0.2)
#Just draw the plot twice
png("test.png")
print(a_plot)
print(a_plot, vp = vp)
dev.off()
Это основано на предоставленном вами коде, но работает очень медленно для большого списка, как отмечено в других комментариях.
new_records = []
for record in records:
new_id = record['id']
new_name = record['name']
new_dict = {'id':new_id, 'name': new_name}
if not any(new_record['id'] == new_id for new_record in new_records):
new_records.append(new_dict)