小编swc*_*hen的帖子

在ggplot2中绘制堆积条上方的和值

如何在ggplot2中的堆积条上方绘制每个类的总和值(在我的情况下:a = 450,b = 150,c = 290,d = 90)?这是我的代码:

#Data
hp=read.csv(textConnection(
"class,year,amount
a,99,100
a,100,200
a,101,150
b,100,50
b,101,100
c,102,70
c,102,80
c,103,90
c,104,50
d,102,90"))
hp$year=as.factor(hp$year)

#Plotting
p=ggplot(data=hp)  
p+geom_bar(binwidth=0.5,stat="identity")+  
aes(x=reorder(class,-value,sum),y=value,label=value,fill=year)+
theme()
Run Code Online (Sandbox Code Playgroud)

r bar-chart ggplot2

9
推荐指数
2
解决办法
1万
查看次数

将全角字符串转换为半角字符串

我怎样才能转换\xef\xbc\xa1b\xef\xbc\x99\xef\xbc\x98\xef\xbc\x97\xef\xbc\x96\xef\xbc\x95\xef\xbc\x94\xef\xbc\x93\xef\xbc\x92\xef\xbc\x91\xef\xbc\x90Ab9876543210?有没有通过正则表达式解决的办法?

\n

test <- dput("\xef\xbc\xa1b\xef\xbc\x99\xef\xbc\x98\xef\xbc\x97\xef\xbc\x96\xef\xbc\x95\xef\xbc\x94\xef\xbc\x93\xef\xbc\x92\xef\xbc\x91\xef\xbc\x90")

\n

regex r

5
推荐指数
1
解决办法
2113
查看次数

ggplot2:无法按x值对x轴进行排序

我在ggplot2中按x值排序x轴有问题:这是下面的代码

#Data
hp=read.csv(textConnection(
"class,year,amount
a,99,100
a,100,200
a,101,150
b,100,50
b,101,100
c,102,70
c,102,80
c,103,90
c,104,50
d,102,90"))
hp$year=as.factor(hp$year)

#Plotting
p=ggplot(data=hp)  
p+geom_bar(binwidth=0.5,stat="identity")+  #
aes(x=reorder(class,amount),y=amount,label=amount,fill=year)+
theme()
Run Code Online (Sandbox Code Playgroud)

结果如下:

在此输入图像描述

如何按acbd对x轴进行排序,其数量按450,290,150,90减少排序.我该怎么办?

sorting r ggplot2

4
推荐指数
1
解决办法
8730
查看次数

标签 统计

r ×3

ggplot2 ×2

bar-chart ×1

regex ×1

sorting ×1