Обратная ориентация числа на отрицательной части оси y (программирование R, ggplot2) - PullRequest
1 голос
/ 27 сентября 2019

Я пытаюсь нарисовать линейный график, используя ggplot2, но, поскольку я все еще неопытен, у меня возникла проблема с обнаружением ошибки в моем коде.

Основная проблема заключается в том, что при создании графикаметки на отрицательной части оси y инвертированы по значению.

Следовательно, точки на отрицательной части декартовой системы координат также расположены неправильно.

Я верю в этоимеет отношение к типу данных, которые я использую для ввода ggplot, но я не могу понять, где я ошибся и как мне изменить мой код.

Я добавляю полный код исгенерированный участок.

vektor1 = c(1:8,1:8,1:8, 1:8)
vektor2 = c(1.2,-0.34,1.1,0.003, 0.67, -0.46, 0.23, 0.695, -1.92,0.04,1.21,0.073, -0.067, 0.146, -0.93, 0.5, 1.2,-1.34,2.3,0.043, 0.57, -0.46, 0.73, 0.895, -1.99,0.04,0.21,0.073, -0.567, 0.146, -0.23, 0.5,0)
vektor3 = c(rep("log2fold>1",times=8), rep("B",times=8), rep("C", times=8), rep("D", times=8),"")
vektor4 = c("p<0.001","p<0.01","p<0.5","p<0.5","p<0.5","p<0.5","","p<0.5","","p<0.001","","","p<0.01","p<0.01","","p<0.5", "","p<0.01","p<0.5","p<0.5","p<0.01","","p<0.5","p<0.01","","p<0.01","","p<0.5","p<0.01","p<0.5","p<0.01","p<0.01","")
vektor5 = c("DA","DA","DA","NE","NE","DA","NE","DA","DA","DA","DA","NE","NE","DA","NE","DA","DA","DA","DA","NE","NE","DA","NE","DA","DA","DA","DA","NE","NE","DA","NE","DA","NE")
data=data.frame(cbind(vektor1,vektor2, vektor3, vektor4, vektor5))


plot = ggplot(data=data, aes(x=data$vektor1, y=as.factor(data$vektor2), group=data$vektor3)) +
geom_line(aes(color=data$vektor3), size=2) +
geom_hline(yintercept = as.numeric(data$vektor2[dim(data)[1]]), size=0.25) +
geom_vline(xintercept = 1.5, size=0.25, color="grey") +
geom_vline(xintercept = 2.5, size=0.25, color="grey") +
geom_vline(xintercept = 3.5, size=0.25, color="grey") +
geom_vline(xintercept = 4.5, size=0.25, color="grey") +
geom_vline(xintercept = 5.5, size=0.25, color="grey") +
geom_vline(xintercept = 6.5, size=0.25, color="grey") +
geom_vline(xintercept = 7.5, size=0.25, color="grey") +
geom_point(aes(color= data$vektor3, shape=data$vektor4, size=data$vektor5)) +
theme_minimal() +
scale_shape_manual(values=c(NA,15,18,19))+
scale_size_manual(values=c(15,15,15))+
scale_color_manual(values=c("white", "cornflowerblue", "seagreen3", "firebrick1", "gold")) +
labs(x="phy", y="log odds", title = "Working title", subtitle = "") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) +
labs(shape="Species label", colour="Petal width label", size="jgagajk") +
geom_segment(aes(x=8.3, xend = 8.3 , y=as.numeric(data$vektor2[dim(data)[1]]), yend = as.numeric(data$vektor2[which.max(as.numeric(as.character(data[,2])))])), size=4, arrow = arrow(length = unit(1,"cm"), type = "closed"), color="grey") +
geom_segment(aes(x=8.3, xend = 8.3 , y=as.numeric(data$vektor2[dim(data)[1]]), yend = as.numeric(data$vektor2[which.min(as.numeric(as.character(data[,2])))])), size=4, arrow = arrow(length = unit(1,"cm"), type = "closed"), color="grey") +
guides(size = FALSE, shape = guide_legend(override.aes = list(size=10)), color = guide_legend(override.aes = list(size=10))) +
theme(plot.margin = margin(2, 2, 2, 2, "cm"), legend.title=element_text(size=35), legend.text= element_text(size=35), axis.text=element_text(size=20), axis.title.y = element_text(hjust = 0.325, vjust = 10 , size = 35), axis.title.x= element_text(size=25), plot.title = element_text(hjust = 0.5, size = 40))
plot

ggsave(paste("uuu.png"), plot, scale = 1, width = 100, height = 40, units = c("cm"), dpi = 300)

enter image description here

...