Reproducing the following base graph with ggplot2

前端 未结 1 1474
离开以前
离开以前 2021-01-02 12:22

I\'d like to reproduce the following base graph with ggplot2. \"enter

Following is the

1条回答
  •  轮回少年
    2021-01-02 12:31

    library("ggplot2")
    p <- ggplot(data=as.data.frame(G), aes(V1, V2)) +
                geom_vline(xintercept=0, colour="green", linetype=2, size=1) +
                geom_hline(yintercept=0, colour="green", linetype=2, size=1) +
                geom_point() +
                geom_text(aes(label=row.names(G)), vjust=1.25, colour="blue") +
                geom_path(data=as.data.frame(con.hull), aes(V1, V2)) +
                geom_segment(data=as.data.frame(E),
                             aes(xend=V1, yend=V2), x=0, y=0,
                             colour="brown", arrow=arrow(length=unit(0.5 ,"cm"))) +
                geom_text(data=as.data.frame(E), aes(label=row.names(E)),
                          vjust=1.35, colour="red") +
                labs(list(x=sprintf("PC1 (%.1f%%)", PC.Percent.SS[1]),
                          y=sprintf("PC2 (%.1f%%)", PC.Percent.SS[2]))) +
                xlim(range(c(E[,1], G[,1]))*(1+r)) +
                ylim(range(c(E[,2], G[,2]))*(1+r))
    
    tmp <- t(sapply(1:(nrow(con.hull)-1),
             function(i) getPerpPoints(con.hull[i:(i+1),])[2, ]))
    p <- p + geom_segment(data=as.data.frame(tmp),
                          aes(xend=V1, yend=V2), x=0, y=0)    
    
    print(p)
    

    ggplot2 example

    0 讨论(0)
提交回复
热议问题