Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 更改原始条形图ggplot2_R_Plot_Ggplot2 - Fatal编程技术网

R 更改原始条形图ggplot2

R 更改原始条形图ggplot2,r,plot,ggplot2,R,Plot,Ggplot2,我想让我的图形原点的一个空格去掉左角350000,17坐标 我的数据集dat: group x y Sens 17 4059 Sens 18 3289 Sens 19 3785 Sens 20 5241 Sens 21 17179 Sens 22 11004 Sens 23 23624 Sens 24 61544 Sens 25 87324 Sens 26 85610 Sens 27 53652 Sens 28 26243 S

我想让我的图形原点的一个空格去掉左角350000,17坐标

我的数据集dat:

group  x       y
Sens 17    4059
Sens 18    3289
Sens 19    3785
Sens 20    5241
Sens 21   17179
Sens 22   11004
Sens 23   23624
Sens 24   61544
Sens 25   87324
Sens 26   85610
Sens 27   53652
Sens 28   26243
Sens 29   10840
Sens 30    3277
Antisens 17   -7145
Antisens 18   -8334
Antisens 19  -10020
Antisens 20  -14247
Antisens 21  -33285
Antisens 22  -32575
Antisens 23  -79349
Antisens 24 -217690
Antisens 25 -338036
Antisens 26 -291708
Antisens 27 -172231
Antisens 28  -86063
Antisens 29  -29685
Antisens 30   -7914
我该怎么做

我想得到这样的东西:

使用的命令行:

d <- ggplot(dat, aes(x=x, y=y, fill=group)) + 
       geom_bar(stat="identity", position="identity") + 
       scale_y_continuous(limits=c(-350000, 90000),breaks=c(90000,0,-90000,-180000,-270000,-350000),labels=abs(c(90000,0,-90000,-180000,-270000,-350000))) + 
       scale_x_continuous(breaks=seq(17,30,by=1), labels=c(17,"",19,"",21,"",23,"",25,"",27,"",29,"")) + 
       xlab("small RNA length [nt]") + ylab("normalized small RNA counts") + 
       scale_fill_manual(values = c("red", "blue"))
d <- d + theme_bw() + 
           theme(axis.line = element_line(colour = "black"), panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + 
           theme(panel.border=element_blank())
d

根据我的评论,geom_段可用于重建轴。我已经调整了轴的限制,以允许额外的空间。我不知道还有其他方法可以继续,尽管我相信会有。我试图对代码中添加的内容进行注释

# Your data [you can use dput(dat) to get structure below]

dat <- structure(list(group = c("Sens", "Sens", "Sens", "Sens", "Sens", 
      "Sens", "Sens", "Sens", "Sens", "Sens", "Sens", "Sens", "Sens", 
      "Sens", "Antisens", "Antisens", "Antisens", "Antisens", "Antisens", 
      "Antisens", "Antisens", "Antisens", "Antisens", "Antisens", "Antisens", 
      "Antisens", "Antisens", "Antisens"), x = c(17L, 18L, 19L, 20L, 
      21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 17L, 18L, 19L, 
      20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L), y = c(4059L, 
      3289L, 3785L, 5241L, 17179L, 11004L, 23624L, 61544L, 87324L, 
      85610L, 53652L, 26243L, 10840L, 3277L, -7145L, -8334L, -10020L, 
     -14247L, -33285L, -32575L, -79349L, -217690L, -338036L, -291708L, 
     -172231L, -86063L, -29685L, -7914L)), .Names = c("group", "x", 
     "y"), class = "data.frame", row.names = c(NA, -28L))


# ---------------------------------------------------------------------------
library(ggplot2)

# Initial plot
d <- ggplot(dat, aes(x=x, y=y, fill=group)) + 
         geom_bar(stat="identity", position="identity") + 
         scale_y_continuous(
                 limits=c(-380000, 90000), # lowered the min limit slightly
                 breaks=c(90000,0,-90000,-180000,-270000,-350000),
                 labels=abs ,  # note the use of abs
                 expand=c(0,0)) + # use expand so axis start exactly at limits
         scale_x_continuous(
                 limits=c(16,30),  # added x-axis limits (min is < your min break)
                 breaks=seq(18,30,by=2), 
                 labels=seq(18,30,by=2) , 
                 expand=c(0,0)) + 
         xlab("small RNA length [nt]") + 
         ylab("normalized small RNA counts") + 
         scale_fill_manual(values = c("red", "blue"))

d <- d + theme_bw() + 
         theme(axis.line = element_blank(), # remove both axis lines
               panel.grid.major = element_blank(), 
               panel.grid.minor = element_blank(),
               panel.border=element_blank())

# Add in segments for the axis - allow a gap at the corner
d + 
geom_segment(x=17,xend=30,y=-380000,yend=-380000) + # x-axis
geom_segment(x=16,xend=16,y=-350000,yend=90000) # y-axis

“dat”是什么样子的?没有它,我们无法运行您的代码。请尝试创建一个最小的可复制示例。为什么不简单地从正在绘制的数据集中删除该数据点?@sebastian-c我认为这与数据点无关,它的todo与在原点相交的轴线有关。微妙的。是的,我希望左边的角落不要碰第二张图片,我想要一个空间而不是一个角落,让你自己的图形设备。