Plotting a 4D graph with the fourth dimension using color (a 3D graph with the fourth dimension represented using colors)

I would like to know how to plot R0 (basic reproduction number of a disease) against three given parameters on a 3D plot where the x-, y-, and z- axes represent the three parameters and a color scheme represents R0. So, the graph should essentially be a 3D plot, but the fourth dimension (depicting R0) should be in terms of a color scheme.
In the current example, I wish to plot R0 against the three parameters beta, p, and phi which could all vary between 0 and 1. The formula for R0 and the parameters are given below.
c = 0.01;
%beta = 0.4;
gamma = 0.2;
theta = 0.2778;
%p = 0.05;
%phi = 0.95;
epsilon = 0.084;
delta = 0.011;
mu = 0.000027;
R0 = (epsilon*c*beta*theta*(mu+(1-phi)*p))/(mu*(mu+p)*(mu+epsilon)*(mu+gamma+delta))
I would highly appreciate if someone could help me on this. Thanks a lot in advance!

Answers (1)

Use "slice".
This will display R0 on predefined planes in 3d space.

12 Comments

Hi @Torsten, thanks a lot for your suggestion. I tried to use "slice" and came up with the following program after consulting the matlab documentation. However, something doesn't seem right with the way that I have defined the slices (which I think I don't understand how to do). Also, I would like to know how to restrict R0 to be less than 5. So, could you please help? Thanks again!
clear all
c = 0.01;
%beta = 0.4;
gamma = 0.2;
theta = 0.2778;
%p = 0.05;
%phi = 0.95;
epsilon = 0.084;
delta = 0.011;
mu = 0.000027;
beta = 0:.1:1;
p = 0:.1:1;
phi = 0:.1:1;
[beta,p,phi] = meshgrid(beta,p,phi);
R0 = (epsilon.*c.*beta.*theta.*(mu+(1-phi).*p))./(mu.*(mu+p).*(mu+epsilon).*(mu+gamma+delta));
betaslice = [0,.1,1];
pslice = 0.5;
phislice = [0,0.2];
slice(beta,p,phi,R0,betaslice,pslice,phislice)
xlabel('\beta')
ylabel('p')
zlabel('\phi')
colorbar
You told MATLAB to plot R0 on six slices (beta=0, beta=0.1, beta=1, p=0.5, phi=0, phi=0.2) and it did.
What do you mean by "restrict R0 to be less than 5" ? You want to plot min(R0,5) ?
Thank you for the clarification! According to the color bar, R0 could go above 450. However, I want to R0 to be less than 5, otherwise it wouldn't make sense epidemiologically. Moreover, is there a way to obtain a graph without using slices, I mean a graph like the one below as this is the kind of graph that I expected as opposed to the one that the above code generates with the "Slice" function?
This is a surface plot for "Intensity" depending on two instead of three parameters. One is radius, the other axis has no name.
Use "surf" to get a plot like the one above.
Since the values for "Intensity" are between -10 and 10, it's probable that you did some mistake in the definition of R0 or that you used a different unit for "Intensity" than in the above graphics.
It might also be the plot of a fourth variable on a surface different from a plane. But it's unclear how the surface was created and what it represents. Maybe it's an isosurface of another variable - only you know.
Thanks, @Torsten! Apologies for the late response. In fact, this is an image that I found on the web at the following link, and it is not relevant to my example. Going back to my original problem, in the 3D plot with slices, what I am still struggling to do is to restrict the plot so that . Since this is a biological model, it would not make sense to have values as large as 450. So, is there a way that I can restrict the R0 values between 0 and 5? Thank you again!
If values for R0 are computed to be greater than 5, then how do you want to plot them ?
You could set the R0 values > 5 to NaN values. These values are not plotted afterwards.
Or you could set them artificially to 5.
But isn't that simply cheating ?
I don't think so as I am only trying to consider epidemiologically meaningful values.
But if your model for R0 gives non-meaningful values, you should start modifying your model instead of modifying the results from the model, shouldn't you ?
Hi again, thanks for the great question. Yes, you're right. I am not sure if I was using accurate terminology when I made it look like R0 values as high as 450 are "epidemiologically meaningless" because any non-negative value of R0 is theoretically possible. That said, there might be a problem with the model when it gives such large values for R0. However, I don't think that there is anything erroneous with my model or the parameter values to the best of my knowledge, on which I might well be wrong as well. In fact, none of the other simulations that I did pertaining to R0 gave results like these. So, I drew similar plots of R0 for three other models that I found in the literature and examined what those graphs look like. Surprisingly, those plots also produced substantially large values for R0 as mine did. I was hence wondering if there are issues with those models as well or if this is a typical phenomenon. May be they didn't figure it out as they didn't go about producing a graph like this, nor did I until I came up with the current graph. Therefore, I believe that this is a question which is worthy of a discussion on its own, perhaps on a separate platform. Thanks for all your inputs.
Another thought that just came to my mind is that we are mainly concerned not so much about the actual value/s of R0 as the behavior of the parameters of interest at/near the threshold R0=1. So, restricting R0 on a smaller interval like [0,2] or [0,5] would help us get a better sense of (closer look at) how the three parameters affect R0 near the threshold (which, in fact, is the purpose of such a graph). If the graph was based on data, then truncating a part of it would certainly constitute an act of cheating, but a case like this, in my opinion, doesn't seem to do so.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 15 Jan 2023

Edited:

on 17 Jan 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!