Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing a triangle with geom_polygon

Tags:

r

ggplot2

Hi there I need some help drawing a simple triangle

library(ggplot2)
library(data.table)

dt.triangle <- data.table(group = c(1,1,1), polygon.x = c(2,4,4), polygon.y = c(1,1,3))

p <- ggplot()
p <- p + geom_polygon(
            data = dt.triangle
            ,aes(
                x=polygon.x
                ,y=polygon.y
                ,group=group
            )
        )
p

I'm not that satisfied with the drawing/rendering of the hypotneuse, somehow I want to draw a line that doesn't show this "saw teeth".

Do I miss something?

For some reason I want to use ggplot2 in combination with geom_polygon.

Any help is appreciated

Tom

like image 617
Tom Martens Avatar asked May 23 '13 14:05

Tom Martens


1 Answers

The effect is because the default rendering engine doesn't use anti-aliasing. If you save as a pdf or svg it will render more smoothly.

Alternatively, you can use a Cairo device:

library(Cairo)
CairoWin() # or perhaps CairoX11()
p
like image 62
James Avatar answered Sep 19 '22 11:09

James