Question: Unable to change point size in plotExpression()
gravatar for kushshah
8 months ago by
University of North Carolina, Chapel Hill, USA
kushshah10 wrote:

Seems relatively basic, but I can't find a way to change graph dynamics using the plotExpression() function in scater. For example, I have the following gene expression plot:

I am coloring points by cell type, but there are so many points and they are too big - therefore, alpha cells seem to trump the other cells because they are near the top of the shading hierarchy.

Specifically, I want to be able to do the following:

  1. Decrease point size
  2. Create and change point borders
  3. Change transparency of points
  4. Change legend title

In general, within plotExpression() and other plotting functions in scater, how are these sorts of changes made to the default graphs? I noticed that plotExpression() can take in an aes() object as an argument - is this the way? If so, how must this be formatted? I tried the following code:

plotExpression(sce, features=rownames(var.out.nospike)[chosen.genes], colour_by = "Characteristics.cell.type.", aesth = aes(size=2) + fontsize

but it results in an unused argument error referring to aesth. I have also tried adding a theme object like this:

plotExpression(sce, features=rownames(var.out.nospike)[chosen.genes]) + theme(axis.text=element_text(size=8)

but I don't think you can specify point size in a theme object. Any help or references to coded examples would be much appreciated!

ADD COMMENTlink modified 8 months ago by Aaron Lun25k • written 8 months ago by kushshah10
Answer: Unable to change point size in plotExpression()
gravatar for Aaron Lun
8 months ago by
Aaron Lun25k
Cambridge, United Kingdom
Aaron Lun25k wrote:

If one were to follow the rabbit hole in ?plotExpression, you would see:

...: Additional arguments for visualization, see ?"scater-plot-args" for details.

From there, you should be able to find a point_size argument that... well, changes the point size. Similarly point_alpha can change the transparency of the points.

Point borders are hard coded. An option could be added, but clearly no one has felt the need for it. If you want to change them, I guess you could operate on the ggplot object to edit the point parameters (e.g., with + geom_point or something).

Legend titles are dependent on the variable name (i.e., the feature name or the metadata column name), which is a fairly sensible and generalizable strategy. If you want to change it, you can either change what the variable is called in the SingleCellExperiment object; or you can edit the ggplot object afterwards.

scater used to have some facilities for operating on the aes objects generated by ggplot2. However, their use required the user to know how the plotting variables were named inside the scater functions - this breaks encapsulation and should not be the user's business or responsibility. Frankly, if a user knows enough to create aes objects, then they should just use ggplot2 directly. scater's plotting functions are intended for quick and convenient visualization - I'm afraid that publication quality plots will require some more manual effort.

ADD COMMENTlink modified 8 months ago • written 8 months ago by Aaron Lun25k

Thanks Aaron. Didn't realize there were extra arguments in scater-plot-args. This is really helpful. In the list of extra arguments, I didn't see any way to add a chart title - is this possible for plotExpression()?

ADD REPLYlink written 7 months ago by kushshah10

Can't you just use ggtitle? See, e.g., Figure 12 here.

ADD REPLYlink modified 7 months ago • written 7 months ago by Aaron Lun25k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 298 users visited in the last hour