[R] Help with Plot

Peter Langfelder peter.langfelder at gmail.com
Tue Aug 4 20:09:40 CEST 2015


Try removing the line

x <- x[order(x[,1], decreasing=TRUE),]


Peter

On Tue, Aug 4, 2015 at 10:58 AM, April Smith <aprilgracesmith at gmail.com> wrote:
> Let me just preface that everything I know about writing code for R is self
> taught so this may be really basic but I can't figure it out!
>
> I am using someone else code to create plots.  I would like to change the
> automatically generated colors to the same colors for every plot.  The
> current code makes the highest line in the graph black, the second highest
> line red, 3rd blue, etc, regardless of what the line represents.  I need to
> create 10 of these plots and it gets confusing when the black line means a
> different thing in each plot!   Here is the line I need to adjust, I just
> don't know how.
>
> lines(1:orders, x[i,], col=i)
>
> Here is the code in entirety:
> plot.hill <- function(x, scales = c(0, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64,
>    Inf), ...) {
>    require(vegan)
>    nsites <- if(is.null(ncol(x))) 1 else ncol(x)
>    x <- renyi(t(x), scales=scales, hill=TRUE)
>    orders <- length(scales)
>    if(nsites > 1) {
>       x <- x[order(x[,1], decreasing=TRUE),]
>       OP <- matrix(".   ", nsites,nsites)
>       colnames(OP) <- rownames(OP) <- rownames(x)
>       for(i in 1:(nsites-1))
>          for(j in (i+1):nsites)
>             if(all(x[i,] > x[j,])) {
>                OP[i,j] <- "<   "
>                OP[j,i] <- "^   "
>             }
>       diag(OP) <- " "
>       OP <- as.data.frame(OP)
>       cat("The arrow < or ^ points to the more diverse site:\n")
>       print(OP, na.print=" ")
>    } else
>       OP <- NULL
>    plot(1:4,1:4,type="n",xlim=c(0.9,orders+0.1),ylim=range(0,x),axes=FALSE,
>       ylab="Hill Diversity Numbers",xlab="Order", ...)
>    axis(2)
>    axis(1, at=1:orders, labels=scales)
>    if(nsites > 1) {
>       for(i in 1:nsites)
>          lines(1:orders, x[i,], col=i)
>       legend("topright", legend=row.names(x), col=1:nsites, lty=1, cex=0.7)
>    } else
>       lines(1:orders, x)
>    invisible(OP)
> }
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list