所以我一直试图在我的直方图上添加 Y 轴。现在我的 Y 比例是离散的,但如果我把它改为连续的,它就不会绘图。我希望代码有一个 y 轴列出有多少海龟。
请让我知道我能做什么,谢谢!
这是我的代码:
library(ggplot2)
library(ggridges)
ggplot(Merge, aes(x = SCL, y = Type, group = Type, fill = Type)) +
geom_density_ridges(stat = "binline", bins = 20, scale = 0.95) +
scale_y_discrete(name ="Type of Turtles", expand = c(-.0, 0.999)) +
scale_x_continuous(expand = c(0, 10), name="Total Length (mm)") +
coord_cartesian(clip = "off") +
theme(panel.grid.major = element_line(colour="grey"), legend.position='none',
panel.grid.major.x = element_blank(), axis.text.x =
element_text(face="bold", size=17, family= "sans", colour = "black"),
axis.text.y = element_text(face="bold", size=17, family= "sans", colour = "black"),
text = element_text(face = "bold", size=17, family= "sans",
colour="black"),
panel.grid.minor.x = element_blank(), panel.border =
element_rect(fill=NA, colour = "black", size=1.25),
panel.background = element_rect(fill='white', colour='black'))
Merge <- read.table(text = '"Turtle_ID","Type","Sex","SCL","Age"
"1","1","Kemps",NA,10,0
"2","2","Kemps",NA,10.2,0
"3","2","Kemps",NA,21,0.75
"4","3","Kemps",NA,10.8,0
"5","3","Kemps",NA,21.4,0.75
"6","4","Kemps","male",10.5,0
"7","4","Kemps","male",18.2,0.75
"8","4","Kemps","male",22,1.75
"9","5","Kemps",NA,10.5,0
"10","6","Kemps",NA,11,0
"11","6","Kemps",NA,22.9,0.75
"12","7","Kemps",NA,10.2,0
"13","7","Kemps",NA,19.4,0.75
"14","8","Kemps","female",11.5,0
"15","8","Kemps","female",21.4,0.75
"16","9","Kemps",NA,11,0
"17","9","Kemps",NA,20.6,0.75
"18","9","Kemps",NA,27.3,1.75
"19","10","Kemps","male",11.1,0
"20","10","Kemps","male",24.1,0.75
"21","11","Kemps",NA,11.3,0
"22","11","Kemps",NA,22.6,0.75
"23","12","Kemps",NA,11.3,0
"24","12","Kemps",NA,23.5,0.75
"25","12","Kemps",NA,29.8,1.75
"26","13","Kemps",NA,10.8,0
"27","13","Kemps",NA,21.5,0.75
"28","14","Kemps","female",11,0
"29","14","Kemps","female",22.4,0.75
"30","14","Kemps","female",30.7,1.75
"31","15","Kemps",NA,11.5,0
"32","15","Kemps",NA,20.7,0.75
"33","15","Kemps",NA,26.8,1.75
"34","16","Kemps","male",11.5,0
"35","16","Kemps","male",23,0.75
"36","17","Kemps","female",12.1,0
"37","17","Kemps","female",25.8,0.75
"38","18","Kemps","female",11.4,0
"39","18","Kemps","female",20.3,0.75
"40","19","Kemps",NA,11.6,0
"41","20","Kemps","male",11,0
"42","20","Kemps","male",21.3,0.75
"43","20","Kemps","male",29.3,1.75
"44","21","Kemps","female",11.2,0
"45","22","Kemps","female",10.9,0
"46","22","Kemps","female",23.8,0.75
"47","23","Kemps",NA,12.4,0
"48","23","Kemps",NA,25.5,0.75
"49","24","Kemps",NA,11.5,0
"50","25","Kemps",NA,11.7,0
"51","25","Kemps",NA,24.6,0.75
"52","25","Kemps",NA,34.9,1.75
"53","26","Kemps","female",10.8,0
"54","26","Kemps","female",21,0.75
"55","27","Kemps",NA,11.8,0
"56","27","Kemps",NA,22.5,0.75
"57","28","Kemps",NA,11.8,0
"58","28","Kemps",NA,21.1,0.75
"59","28","Kemps",NA,27.3,1.75
"60","28","Kemps",NA,35.1,2.75
"61","29","Kemps",NA,11.6,0
"62","29","Kemps",NA,23.8,0.75
"63","30","Kemps","female",11.7,0
"64","31","Kemps","female",12,0
"65","31","Kemps","female",21.8,0.75
"66","31","Kemps","female",26.1,1.75
"67","32","Kemps",NA,12,0
"68","32","Kemps",NA,24.8,0.75
"69","33","Kemps",NA,12,0
"70","33","Kemps",NA,26.1,0.75
"71","34","Kemps","female",12,0
"72","34","Kemps","female",25,0.75
"73","34","Kemps","female",34.5,1.75
"74","35","Kemps",NA,12,0
"75","35","Kemps",NA,25.9,0.75
"76","35","Kemps",NA,36.2,1.75
"77","35","Kemps",NA,43.7,2.75
"78","36","Kemps",NA,11.6,0
"79","36","Kemps",NA,20,0.75
"80","36","Kemps",NA,21.4,1.75
"81","37","Kemps",NA,12.8,0
"82","37","Kemps",NA,22.6,0.75
"83","37","Kemps",NA,27.2,1.75
"84","37","Kemps",NA,36.2,2.75
"85","38","Kemps",NA,11.7,0
"86","38","Kemps",NA,21.7,0.75
"87","38","Kemps",NA,30.8,1.75
"88","39","Kemps",NA,11.9,0
"89","39","Kemps",NA,22.5,0.75
"90","39","Kemps",NA,28,1.75
"91","40","Kemps","female",11.7,0
"92","40","Kemps","female",22.8,0.75
"93","41","Kemps",NA,12.7,0
"94","41","Kemps",NA,26,0.75
"95","42","Kemps","male",12.5,0
"96","42","Kemps","male",24.9,0.75
"97","42","Kemps","male",30.2,1.75
"98","42","Kemps","male",34.7,2.75
"99","43","Kemps",NA,12.4,0
"100","43","Kemps",NA,26.1,0.75', sep = ",")