我准备了一个MWE,希望能得到关于如何在x轴上的不同位置为分组条形图设置刻度和标签的帮助。
library(ggplot2)
library(reshape2)
data <- data.frame(name = c("X","Y","Z"), A = c(2,4,6), B = c(1,3,4), C = c(3,4,5))
data <- melt(data, id = 1)
ggplot(data, aes(name,value)) +
geom_bar(aes(fill = variable), position =
问题
我试图根据上一个小面组"Step4“的递减值,对桶图的Y轴进行排序,并有一个共同的Y轴标签。有关于排序所有方面组本身的建议,但是如何处理一个方面组的共同y轴标签和值。我已经附上了一个样本数据和代码,为初步的绘图,以了解问题。提前谢谢。
数据
码
library(ggplot2)
library(reshape2)
#reading data
data <- read.csv(file = "./sample_data.csv", stringsAsFactors = TRUE)
#reshaping data in longer format usin
我在ggplot中制作了一个图,其中x轴标签包含不同蛋白质的名称,我遇到了麻烦,因为其中一些名称太长,标签变得太大,以至于很难看到图。
有没有什么方法可以减少x轴标签中的字符数,而不是“打印”更大的图形?
下面的例子说明了我的问题:
library(ggplot2)
dat <- mtcars
# Make the x-axis labels very long for this example
dat$car <- paste0(rownames(mtcars),rownames(mtcars),rownames(mtcars),rownames(mtcars))
ggplot
我正试图使用ggplot2在R中制作一个100%的堆叠条形图,并获得真实计数的数据标签,而不是一个百分比。当我尝试这样做的时候,我会得到一些小的条形图,标签就在图的另一边。我可以得到一个条形图和计数在酒吧,我知道这里已经有很多问题,如何得到百分比,但我没有找到任何答案,我正在寻找的。这是为了工作,但是一些模拟数据类似于:
dat <- read.table(text = "assessment User N
missingcomma Sara 5
notcapitolized Sara 2
noindent Sara 1
missingcomma Jason 1
notcapit
在使用ggplot绘制条形图时,我遇到了获取首选的千位分隔符的问题。我希望用点而不是逗号来分隔数千个字符。如下所示,它没有分隔符:
require(ggplot2)
require(scales)
options(scipen=10)
D = data.frame(x=c(1,2),y=c(1000001,500000))
p = ggplot(D,aes(x,y)) + geom_bar(stat="identity")
p
像这样,它给出了一个逗号:
p + scale_y_continuous(labels=comma)
如何得到一个点作为千位分隔符?除了上的一些示例
我想研究一下带有ggplot的directlabels包。我试图在一个简单的线状图的端点绘制标签;但是,这些标签是由绘图面板裁剪的。(我打算在一幅图中画出大约10个财政时间序列,我认为直接标签是最好的解决办法。)
我可以想象可能会有另一种使用annotate或其他geoms的解决方案。但我想用直接标签来解决这个问题。请参阅下面的代码和图像。谢谢。
library(ggplot2)
library(directlabels)
library(tidyr)
#generate data frame with random data, for illustration and plot:
x &l
我正在使用以下代码:
ggplot2::ggplot(gtfDf, ggplot2::aes(x = type)) +
ggplot2::geom_bar(position = ggplot2::position_dodge(width = 2)) +
ggplot2::xlab('Type of feature') +
ggplot2::ylab('Number of features') +
ggplot2::ggtitle('Number of features of each type in the GTF file'