x
and y
are the coordinates of points, pch
is the symbol for points, cex
is the size of a point, and col
is color. To find out what are the options for plotting graphs in R, run the command ?par
. plot(x=1:10, y=rep(5,10), pch=19, cex=3, col="dark red") points(x=1:10, y=rep(6, 10), pch=19, cex=3, col="557799") points(x=1:10, y=rep(4, 10), pch=19, cex=3, col=rgb(.25, .5, .3))
rgb(10, 100, 100, maxColorValue=255)
command rgb(10, 100, 100, maxColorValue=255)
.alpha
parameter (from 0 to 1): plot(x=1:5, y=rep(5,5), pch=19, cex=12, col=rgb(.25, .5, .3, alpha=.5), xlim=c(0,6))
adjustcolor
from the grDevices
package. For fun, let's also paint the background of the graphics in gray using the par()
function to set the graphics settings. par(bg="gray40") col.tr <- grDevices::adjustcolor("557799", alpha=0.7) plot(x=1:5, y=rep(5,5), pch=19, cex=12, col=col.tr, xlim=c(0,6))
colors() # List all named colors grep("blue", colors(), value=T) # Colors that have "blue" in the name
pal1 <- heat.colors(5, alpha=1) # 5 colors from the heat palette, opaque pal2 <- rainbow(5, alpha=.5) # 5 colors from the heat palette, transparent plot(x=1:10, y=1:10, pch=19, cex=5, col=pal1)
plot(x=1:10, y=1:10, pch=19, cex=5, col=pal2)
colorRampPalette
. Note that colorRampPalette
returns a function that can be used to generate as many colors from this palette as needed. palf <- colorRampPalette(c("gray80", "dark red")) plot(x=10:1, y=1:10, pch=19, cex=5, col=palf(10))
colorRampPalette
, you need to use the alpha=TRUE
parameter: palf <- colorRampPalette(c(rgb(1,1,1, .2),rgb(.8,0,0, .7)), alpha=TRUE) plot(x=10:1, y=1:10, pch=19, cex=5, col=palf(10))
# If you don't have R ColorBrewer already, you will need to install it: install.packages("RColorBrewer") library(RColorBrewer) display.brewer.all()
brewer.pal
. In order to use it, you only need to select the desired palette and the number of colors. Let's take a look at some RColorBrewer
palettes: display.brewer.pal(8, "Set3")
display.brewer.pal(8, "Spectral")
display.brewer.pal(8, "Blues")
RColorBrewer
palettes in graphs: pal3 <- brewer.pal(10, "Set3") plot(x=10:1, y=10:1, pch=19, cex=4, col=pal3)
extrafont
package: install.packages("extrafont") library(extrafont) # Import system fonts - may take a while. font_import() fonts() # See what font families are available to you now. loadfonts(device = "win") # use device = "pdf" for pdf plot output.
library(extrafont) plot(net, vertex.size=30) plot(net, vertex.size=30, vertex.label.family="Arial Black" )
# First you may have to let R know where to find ghostscript on your machine: Sys.setenv(R_GSCMD = "C:/Program Files/gs/gs9.10/bin/gswin64c.exe") # pdf() will send all the plots we output before dev.off() to a pdf file: pdf(file="ArialBlack.pdf") plot(net, vertex.size=30, vertex.label.family="Arial Black" ) dev.off() embed_fonts("ArialBlack.pdf", outfile="ArialBlack_embed.pdf")
Source: https://habr.com/ru/post/263947/
All Articles