Reputation: 4421
Using R
and VennDiagram
1.6.9, I want to draw a triple Venn diagram and display shares rather than absolute values. The internal consistency check however can't deal with rounding errors:
draw.triple.venn(area1=0.89, area2=round(0.481, 2), area3=0.5,
n12=0.46, n23=0.4, n13=0.47)
The error due to rounding is extremely small:
> round(0.48, 2)-0.46-0.4+0.38
[1] -5.551115e-17
Using the complete number, i.e. round(0.48, 3)
it all works fine, but I don't want that (my real data has a lot more digits). Is there a way to overrun internal consistency checks? Or is there maybe a better way to display shares?
Upvotes: 0
Views: 137
Reputation: 11430
Firstly, note that the draw.triple.venn
function has parameters print.mode
and sigdigs
, which might be helpful to you. If those are not enough, you may try hacking the output, by simply replacing the values of all labels with improved values to your taste. Here is an example:
grid.newpage()
draw.triple.venn(area1=0.89, area2=0.481, area3=0.5,
n12=0.46, n23=0.4, n13=0.47, n123=0.38)
grobjs = grid.ls() # List of all objects on the diagram
for (o in grobjs$name) {
# Pick out all text labels
if (grepl(".text.", o) == 1) {
# Re-format their value
old_value = as.numeric(grid.get(o)$label)
new_value = sprintf("%0.2f", old_value) #
if (new_value != "NA") {
grid.edit(o, label=new_value, redraw=FALSE)
}
}
}
grid.refresh()
Upvotes: 1