0

I am trying to draw Density ridgeline plots. So I went to see Introduction to ggridges. Ridgelines can be drawn at the moment, but there was a problem when painting Density ridgeline plots. But I get this error: Error in data.frame(..., check.names = FALSE). How do I modify my code?

I first tried geom_density_ridges() with my own data, but showed the following error:

Error in data.frame(..., check.names = FALSE).

So I tried R's iris dataset and still showed that same error.

library(ggplot2)
library(ggridges)
data2=iris
 ggplot(iris, aes(x = Sepal.Length, y = Species)) + geom_density_ridges()

Picking joint bandwidth of 0.181

Don't know how to automatically pick scale for object of type quosure/formula. Defaulting to continuous. Error in data.frame(..., check.names = FALSE) : 参数值意味着不同的行数: 2, 1536

Here's an attempt on my own data set:

data1<-read.table(file="greatwalldatatest.txt",header=T,sep="\t",fileEncoding = "UTF-16")
 ggplot(data1, aes(data1$longitude, data1$dynasty, height = data1$elevation, group = data1$dynasty)) + 
+   geom_density_ridges(stat = "identity", scale = 1)
 ggplot(data1, aes(x = data1$elevation, y = data1$dynasty)) + geom_density_ridges()

Picking joint bandwidth of 70.6 Don't know how to automatically pick scale for object of type quosure/formula. Defaulting to continuous. Error in data.frame(..., check.names = FALSE) : 参数值意味着不同的行数: 2, 1536

Initially I wanted to use ‘geom_density_ridges()’ to depict the elevation changes of the data points for the three periods, but for now I seem to need help! thank you very much!

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
soda310
  • 1
  • 1

1 Answers1

1

You should really focus on cleaning up your code. It will help you debug easier and will be more polite of you when posting to ask questions. It's hard to understand exactly what you're trying to do, but when using library(ggridges) your x value must be numeric and your y value must be categorical.

Also since you're using ggplot2 you do not need to use data$column_name syntax when creating your plot. Here is an example using iris below.

library(tidyverse)
library(ggridges)
#> 
#> Attaching package: 'ggridges'
#> The following object is masked from 'package:ggplot2':
#> 
#>     scale_discrete_manual


iris %>% 
  ggplot(aes(x = Sepal.Length, y = Species)) + 
  geom_density_ridges()
#> Picking joint bandwidth of 0.181

Created on 2019-01-19 by the reprex package (v0.2.1)

dylanjm
  • 2,011
  • 9
  • 21