How to include superscripts and subscripts on axis from hist3d plots? plot3D package

Hello everyone

I need help to finish some hist3D plots using plot3D package.

The problem is that I don't know how to include superscripts and subscripts in the axis names of this kind of plots. I've tried several codes posted in this website but anyone works on hist3D plot.

I have this example:


VV <- volcano[seq(1, 87, 15), seq(1, 61, 15)]
hist3D(z = VV, scale = F, expand = 0.02, border = "black")
# And I want to include the axis names as follow:
# xlab = "NH4 (mg L-1)"  ## The number 4 has to be subscript and -1 has to be superscript
# ylab = "Irradiance (mu mol m^2 s^-1)" ## 2 and -1 have to be superscripts
# zlab = "Concentration (g L^-1)"  ## -1 has to be superscript

# I've tried the following codes but anyone works:

hist3D(z = VV, scale = F, expand = 0.02, border = "black", xlab = expression( "NH[4] (mg L"^-1)), 
ylab = expression("Irradiance (mu mol m"^2 "s"^-1)), zlab = expression("Concentration (g L"^-1)))

hist3D(z = VV, scale = F, expand = 0.02, border = "black", xlab = expression(paste("NH[4] (mg L"^-1))), 
ylab = expression(paste("Irradiance (mu mol m"^2 "s"^-1))), zlab = expression(paste("Concentration (g L"^-1))))

If somebody knows how to fix this problem I will appreciate it a lot

Have you tried using plotmath expressions in your axis labels?

I don’t know if that will work, since I’m not sure what the hist3D() function you are using is. The only package loaded in your code is scatterplot3d, but that package doesn’t have a hist3D() function.

It would help a lot if you could turn your question into a small reproducible example that contains all the necessary library() statements and self-contained code that somebody else can run.

What’s even more helpful is if you can run your example through the reprex package before posting. reprex formats the example for sharing, including not only the code but also all the output and plots. That makes it much easier for helpers to understand your problem quickly and suggest solutions without lots of back and forth! :grin:

1 Like

Hello jcblum, sorry, my mistake. The package is plot3D, not scatterplot3d

After searching for a few hours I realized that the function "expression" does not work with plots from plot3D package.
The solution was to add text to plots with "text3D" function, it requires a lot of patience since I had to find the right location, but it works.


VV <- volcano[seq(1, 87, 15), seq(1, 61, 15)]
hist3D(z = VV, scale = F, expand = 0.02, border = "black")
text3D(1, 1, 1, labels = expression(NH[4]~(mg~g^{-1})), add = TRUE)

Created on 2018-10-29 by the reprex package (v0.2.1)

"1,1,1" refers to the coordinates of the axis labels

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.