condensing y axis of values for an eventual 2D color gradient plot

I will attempt to explain my objective the best I can...

Let's say I have the following code

age1 <- 7.4832653674979620E+003
prof1 <- data.frame(c(1:1491),seq(0,3.0734451332212645E-046,length.out=1491)) # zone, luminosity
age2 <- 1.2346702987925202E+005
prof2 <- data.frame(c(1:1491),seq(0,3.0631080237264987E-046,length.out=1491))
age1000 <- 1.2753669357777405E+010
prof1000 <- data.frame(c(1:3398),seq(0,.8498789846917101E-001,length.out=3398))
age6062 <- 2.4189944009350475E+010
prof6062 <- data.frame(c(1:1874),seq(0,0,length.out=1874))

I intend to create a 2D color gradient plot of these values, with ages on the x,zones on the y axis, and luminosity on the z axis.

As you can probably tell, the lengths for the vectors in the data frame that represent zones are not equal length with one another. Conceptually, for my code, zones represent slices of a star, as you sliced it like an onion. The first element in the zones vectors, which is 1 for all the vectors, represents the surface of the star, and the maximum zone number, which is different for all the zone vectors, represents the star center.

I want to represent on the y axis NOT zone number, or as an axis of discrete numbers, but the location within the star with respect to surface at zone 1 and the center at zone (max zone number for that profile file), kind of like a gradient or spectrum.

Is there a way to write how to represent all these columns of zones and reconcile into sort of a gradient-like y axis, where the top of the y axis is the surface, and the bottom of the y axis is the center? Ultimately, I want to do is to create a 2D color gradient plot with age on x axis, the location of the luminosity values on the y axis, and a color gradient illustrating the magnitude of these luminosity numbers at this particular location in the star.

Apologies, since you can tell I am an astronomer, I did not know how to ask this with computer science lingo. If this too hefty of a ask, could you kindly point me to the right direction/resources so I may learn how to accomplish this task? If there is still confusion, please ask again and I can clarify anything.

If I understand you correctly, you could get what you want with

prof1 <- data.frame(zone = c(0:1490)/-1490,seq(0,3.0734451332212645E-046,length.out=1491))

This would make the surface have a y value of 0 and the center have a y value of -1 and the y axis would be in units of each star's radius. Does that make sense?
You might also want to bin the luminosity and average the values so that you have 50 or 100 values along the y axis. I do not know how many values is enough but, unless the graph will be physically large, I don't think 1500 different values will really be discernible and the plotting will get slow if you have many x values.

Ok , but how do I set this automatically for all the zone vectors? Not all of them are split into 1490 zones for the star.

However you are constructing your data frames, you can at least rescale the zone column using the result of nrow()

> prof1 <- data.frame(zone = c(0:1490),Lum = seq(0,3.0734451332212645E-046,length.out=1491))
> prof1 <- data.frame(zone = c(0:1490),Lum = seq(0,3.0734451332212645E-046,length.out=1491))
> prof1$zone <- prof1$zone/-(nrow(prof1) - 1)
> head(prof1)
           zone          Lum
1  0.0000000000 0.000000e+00
2 -0.0006711409 2.062715e-49
3 -0.0013422819 4.125430e-49
4 -0.0020134228 6.188145e-49
5 -0.0026845638 8.250859e-49
6 -0.0033557047 1.031357e-48
> tail(prof1)
           zone          Lum
1486 -0.9966443 3.063132e-46
1487 -0.9973154 3.065194e-46
1488 -0.9979866 3.067257e-46
1489 -0.9986577 3.069320e-46
1490 -0.9993289 3.071382e-46
1491 -1.0000000 3.073445e-46

If I have many of these data frames and zones/luminosity, is there a way to scale them from whatever their lengths are: 1441, 3789, 4056, etc., to a length of 200?

You can use the cut() function to define bins and then average the Lum column for each bin. I chose the labels to represent the maximum value in each bin so the bin labeled -0.995 contains the data where the scaled zone was between -1 and -0.995.

prof1 <- data.frame(zone = c(0:1490),Lum = seq(0,3.0734451332212645E-046,length.out=1491))
prof1$zone <- prof1$zone/-(nrow(prof1) - 1)
CUTS <- seq(-1, 0, length.out = 201)
prof1$BIN <- cut(prof1$zone, breaks = CUTS, include.lowest = TRUE, labels = CUTS[2:201])

#Calculate average values for each bin
prof1Avg <- prof1 %>% group_by(BIN) %>% summarize(AvgLum = mean(Lum))

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.