Im working in R with the ggplot2 package.
Im using the geom_contour_filled function.
My data is from an excel file with scientific measurements.
In column 1 there always is the Date. I have about 20 different Dates. In column 2 there is the depth in which the value in column 3 was measured.
[Excel](https://i.sstatic.net/Gsn“your text“kXEwQ.png)
Excel
First I interpolated the data from my excel file because as far as i understood the function would not work with the original dataset because the values in column 2 are different for every date.
Then i got my dataframe.
Dataframe
Now my code for ggplot2 is:
library(ggplot2)
s <- ggplot(data = Dataframe, aes(x = V1,y = V2, z = as.numeric(V3)))
s + geom_contour_filled() +
xlab("D*atum") + ylab("Tiefe [m]") +
scale_y_continuous() +
scale_x_date(d*ate_breaks = "1 month", date_labels = "%Y-%m-%d") +
geom_vline(xintercept = Dataframe$V1, linetype = "dashed") +
ggtitle("Diatomeen") +
theme(axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(hjust = 0.5))`**
This gives out pretty nice plot.
When i add “fill = V3”, the hole plot is grey.
Plot with fill = V3
But then when i add scale_fill_gradient to adjust the colour of the plot, R says:
Warning message:
The following aesthetics were dropped during statistical transformation: fill.
ℹ This can happen when ggplot fails to infer the correct grouping structure in the data.
ℹ Did you forget to specify a group
aesthetic or to convert a numerical variable into a
factor?
Why is that so?
In my dataframe column 1 has the class “Date” and column 2 + 3 are numerics.
When i try to transform column 2 to a factor R and than run the script with ggplot2 R says:
Error in scale_y_continuous()
:
! Discrete values supplied to continuous scale.
ℹ Example values: 0, 0.5, 1, 1.5, and 2
My goal is to adjust the colour of the plot with scale_colour_gradient and I want a seamless colour fade.
In the best case I want red for the high values, then yellow and then blue for the lower values.
Leon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.