## Adjusting point size in R plots.

The trick here is to manage the pch and cex arguments in the plot function.  You can look at more information on these arguments in ?plot, ?par and ?points in the R environment (search for cex and pch).  In general the pch argument controls which type of figure is placed in a specific point.  You can have circles, triangles, squares…  The cex argument controls the amount by which the chosen symbol is magnified.  So you can make symbols bigger or smaller.  In my case I wanted to make them smaller because the size of the original ones was making the plot look funny.  This is the command I used:

```﻿﻿﻿plot(variable, type='o' , pch=10, cex=.2)
```

This scales the symbols to a size that is manageable for me.  for the curious: pch=10 is a cool x inside a circle thingi :) I'm fascinated with how technology and science impact our reality and am drawn to leverage them in order to increase the potential of human activity.
This entry was posted in commands, R. Bookmark the permalink.

### 2 Responses to Adjusting point size in R plots.

1. Luisa Riato says:

Hi Joel, I’m not sure if you can help? Below is a code that works using the plot() function to run a 2D scatterplot of Height vs Weight where points are classed as “Good”, “Fair”, “Poor” based on whether the Class value is 1, 2 or 3, respectively. Points for “Good” are bright green, “Fair”, olive green and Poor, red. All points are the same size (pch=19). Is it possible to have different sizes and transparency for each data point depending on what each point is assigned in the “Group” column: either an Opaque and Small size point, Semi-transparent and Medium sized, or 100% Transparent and Large size point. Should I create two separate columns for Point size and transparency? Thanks for your ideas!

df
# Group Class Height Weight
# 1 Opaque small 1 0.831777874 0.859223152
# 2 Semi-transprnt med 2 0.751019511 0.807521752
# 3 Semi-transprnt med 1 0.751019511 0.807521752
# 4 Transprnt large 3 0.527390539 0.599957241
# 5 Transprnt large 3 0.527390539 0.599957241

color <- c(rgb(0, 1, 0, 1), rgb(0.5, 0.5, 0), rgb(1, 0, 0))
plot(x=c(0.0, 0.5, 0.5, 0.0, 0.0), y=c(0.0, 0.0, 0.5, 0.5, 0.0),
type='l', col='gray', lwd=2,xlab='Height', ylab='Weight',
xlim=c(1,0), ylim=c(1, 0))
par(new=T)
plot(x=c(0.0, 0.5, 0.5, 0.0, 0.0), y=c(0.5, 0.5, 1, 1, 0.5),
type='l', col='gray', lwd=2, xlab='', ylab='',
xlim=c(1, 0.0), ylim=c(1, 0.0), axes=F)
par(new=T)
plot(x=c(0.5, 1, 1, 0.5, 0.5), y=c(0.0, 0.0, 0.5, 0.5, 0.0),
type='l', col='gray', lwd=2,
xlab='', ylab='', xlim=c(1, 0.0), ylim=c(1, 0.0), axes=F)
par(new=T)
plot(x=c(0.5, 1, 1, 0.5, 0.5), y=c(0.5, 0.5, 1, 1, 0.5), type='l',
col='gray', lwd=2, xlab='', ylab='',
xlim=c(1, 0.0), ylim=c(1, 0.0), axes=F)
par(new=T)
for (i in 1:3) {
plot(Height[Class==i], Length[Class==i], xlim=c(0, 1), ylim=c(0, 1),
col=color[i], pch=19, xlab='', ylab='', axes=F)
par(new=T)
}
legend(0.8, 0.586,legend=c('Good', 'Fair', 'Poor'), pch=19,
col=color, title='Class', cex=0.75)

• joelgranados says:

Hey Luisa.sorry for the late reply. Are you still having issues?