首页 > 解决方案 > 用 ggplot 改变 ylim

问题描述

ggplot(parte2, aes(fct_reorder(INDICE, TIEMPO2, min), y=value, color = variable),ylim=c(0,7)) + 
geom_point(aes(y = TIEMPO1, col = "f1(v)")) + 
geom_point(aes(y = TIEMPO2, col = "f2(v)")) + 
geom_point(aes(y = TIEMPO3, col = "f3(v)")) +
labs(title="Tiempos obtenidos", x ="Identificador Prueba", y = "Tiempo en segundos")

我有这段代码,但是当我尝试打印绘图时,它显示如下:

在此处输入图像描述

是否可以更改轴 y 以每 0.5 打印一个值?我的意思是从 0 到 7 每 0.5

当我scale_y_discrete(limits=c(0,7), breaks=seq(0,7, by=0.5))在图中没有使用任何内容时,会出现以下消息:

    Warning messages:
1: Continuous limits supplied to discrete scale.
Did you mean `limits = factor(...)` or `scale_*_continuous()`? 
2: Removed 42 rows containing missing values (geom_point). 
3: Removed 42 rows containing missing values (geom_point). 
4: Removed 42 rows containing missing values (geom_point). 
5: Position guide is perpendicular to the intended axis. Did you mean to specify a different guide `position`? 

我的数据如下:

structure(list(V1 = c("8600108166784055888L", "-6507824305763562165L", 
"-1372751961323668699L", "2774902296422635368L", "8972986591681446237L"
), V2 = c(12L, 18L, 6L, 2L, 4L), V3 = c("3,51", "1,67", "1,42", 
"3,30", "3,00"), V4 = c("0,22", "0,50", "0,55", "0,60", "0,60"
), V5 = c("1,05", "3,60", "1,28", "4,36", "1,71")

标签: rggplot2plot

解决方案


这可以工作:

library(ggplot2)
#Code
ggplot(parte2, aes(fct_reorder(INDICE, TIEMPO2, min),
                   y=value, color = variable),ylim=c(0,7)) + 
  geom_point(aes(y = TIEMPO1, col = "f1(v)")) + 
  geom_point(aes(y = TIEMPO2, col = "f2(v)")) + 
  geom_point(aes(y = TIEMPO3, col = "f3(v)")) +
  scale_y_discrete(breaks=as.character(seq(0,7, by=0.5)))+
  labs(title="Tiempos obtenidos",
       x ="Identificador Prueba",
       y = "Tiempo en segundos")

推荐阅读