d <- data.frame(
u = c(10, 20, 30),
v = c(40, 80, 90),
w = c(20, 50, 40))
px <- seq(as.POSIXct("2023-01-01"),
as.POSIXct("2023-03-01"), by = "month")
rownames(d) <- px
library(kableExtra)
kable(d) |> kable_classic("striped", full_width = F)
|
|
u
|
v
|
w
|
|
2023-01-01
|
10
|
40
|
20
|
|
2023-02-01
|
20
|
80
|
50
|
|
2023-03-01
|
30
|
90
|
40
|
write.csv(d,file = "barplot_py.csv", quote = F)
COL <- c(rgb(255, 0, 255, 55, max = 255),
rgb( 0, 0, 255, 55, max = 255),
rgb( 0, 255, 0, 55, max = 255))
m <- as.matrix(d)
i <- 1
barplot(m[i, ],col = COL[2],
main = rownames(m)[i],
xlab = "項目ラベル",
ylab = "y軸ラベル [単位]")
abline(h = seq(0,100,5), ity = 2, col = gray(0.5,0.25))
## Warning in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): "ity"
## はグラフィックスパラメータではありません

barplot(t(m), col = COL,
main = "積上棒フラフ",
xlab = "項目ラベル",
ylab = "y軸ラベル[単位]")
abline(h = seq(0, 300, 50), lty = 2, col = gray(0.5,0.25))
legend("topleft", fill = COL, legend = colnames(m))

barplot(m, col = COL,
main = "積上棒グラフ",
xlab = "項目ラベル",
ylab = "y軸ラベル[単位]")
abline(h = seq(0, 300, 50), lty = 2, col = gray(0.5, 0.25))
legend("topleft", fill = COL, legend = rownames(m))

barplot(m, col = COL, beside = T,
main = "集合棒グラフ",
xlab = "項目ラベル",
ylab = "y軸ラベル[単位]")
abline(h = seq(0, 100, 20), lty = 2, col = gray(0.5, 0.25))
legend("topleft", fill = COL, legend = rownames(m))

barplot(t(m), col = COL, beside = T,
main = "集合棒グラフ",
xlab = "項目ラベル",
ylab = "y軸ラベル[単位]")
abline(h = seq(0, 100, 20), lty = 2, col = gray(0.5, 0.25))
legend("topleft", fill = COL, legend = colnames(m))

library(plotly)
## 要求されたパッケージ ggplot2 をロード中です
##
## 次のパッケージを付け加えます: 'plotly'
## 以下のオブジェクトは 'package:ggplot2' からマスクされています:
##
## last_plot
## 以下のオブジェクトは 'package:stats' からマスクされています:
##
## filter
## 以下のオブジェクトは 'package:graphics' からマスクされています:
##
## layout
px.g <- format(px, "%Y年%m月")
plot_ly(type = "bar") |>
add_trace(x = px.g, y = d$u, name = "u", marker = list(color = COL[1])) |>
add_trace(x = px.g, y = d$v, name = "v", marker = list(color = COL[2])) |>
add_trace(x = px.g, y = d$w, name = "w", marker = list(color = COL[3])) |>
layout(barmode = "group",
title = "集合棒グラフ",
xaxis = list(title = "項目ラベル"),
yaxis = list(title = "y軸ラベル[単位]"))
## Warning: Can't display both discrete & non-discrete data on same axis
dt <- as.data.frame(t(m))
rn <- rownames(dt)
plot_ly(type = "bar") |>
add_trace(x = rn, y = dt[, 1], name = px.g[1], marker = list(color = COL[1])) |>
add_trace(x = rn, y = dt[, 2], name = px.g[2], marker = list(color = COL[2])) |>
add_trace(x = rn, y = dt[, 3], name = px.g[3], marker = list(color = COL[3])) |>
layout(barmode = "group",
title = "転置したグラフ",
xaxis = list(title = "項目ラベル"),
yaxis = list(title = "y軸ラベル[単位]"))
## Warning: Can't display both discrete & non-discrete data on same axis
import pandas as pd
d = pd.read_csv("barplot_py.csv")
d = d.rename(columns = {"Unnamed: 0": "px"})
import numpy as np
import matplotlib.pyplot as plt
plt.title("棒グラフ")
plt.xlabel("項目ラベル")
plt.ylabel("y軸ラベル[単位]")
pos = np.arange(len(d))
plt.xticks(pos, d["px"])
## ([<matplotlib.axis.XTick object at 0x000001B8BBA739E0>, <matplotlib.axis.XTick object at 0x000001B8BBA739B0>, <matplotlib.axis.XTick object at 0x000001B8BB63A690>], [Text(0, 0, '2023-01-01'), Text(1, 0, '2023-02-01'), Text(2, 0, '2023-03-01')])
plt.grid(linestyle = "--", axis = "y", color = (0.8, 0.8, 0.8, 0.25))
plt.bar(x = pos, height = np.array(d["u"]), color = (1.0, 0.0, 1.0, 0.2))
plt.show()
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 36600 (\N{CJK UNIFIED IDEOGRAPH-8EF8}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12521 (\N{KATAKANA LETTER RA}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12505 (\N{KATAKANA LETTER BE}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12523 (\N{KATAKANA LETTER RU}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 65339 (\N{FULLWIDTH LEFT SQUARE BRACKET}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 21336 (\N{CJK UNIFIED IDEOGRAPH-5358}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 20301 (\N{CJK UNIFIED IDEOGRAPH-4F4D}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 65341 (\N{FULLWIDTH RIGHT SQUARE BRACKET}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 26834 (\N{CJK UNIFIED IDEOGRAPH-68D2}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12464 (\N{KATAKANA LETTER GU}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12501 (\N{KATAKANA LETTER HU}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 38917 (\N{CJK UNIFIED IDEOGRAPH-9805}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 30446 (\N{CJK UNIFIED IDEOGRAPH-76EE}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)

import numpy as np
import matplotlib.pyplot as plt
plt.title("集合棒グラフ")
plt.xlabel("項目ラベル")
plt.ylabel("y軸ラベル[単位]")
pos = np.arange(len(d))
plt.xticks(pos, d["px"])
## ([<matplotlib.axis.XTick object at 0x000001B8BBAE77A0>, <matplotlib.axis.XTick object at 0x000001B8BBAE7D40>, <matplotlib.axis.XTick object at 0x000001B8BBA720F0>], [Text(0, 0, '2023-01-01'), Text(1, 0, '2023-02-01'), Text(2, 0, '2023-03-01')])
plt.grid(linestyle = "--", axis = "y", color = (0.8, 0.8, 0.8, 0.25))
width = 1/(len(d)+1)
plt.bar(x = pos - width, height = d["u"], width = width, color = (1.0, 0.0, 1.0, 0.2))
plt.bar(x = pos, height = d["v"], width = width, color = (0.0, 1.0, 0.0, 0.2))
plt.bar(x = pos + width, height = d["w"], width = width, color = (0.0, 0.0, 1.0, 0.2))
plt.show()
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 36600 (\N{CJK UNIFIED IDEOGRAPH-8EF8}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12521 (\N{KATAKANA LETTER RA}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12505 (\N{KATAKANA LETTER BE}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12523 (\N{KATAKANA LETTER RU}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 65339 (\N{FULLWIDTH LEFT SQUARE BRACKET}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 21336 (\N{CJK UNIFIED IDEOGRAPH-5358}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 20301 (\N{CJK UNIFIED IDEOGRAPH-4F4D}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 65341 (\N{FULLWIDTH RIGHT SQUARE BRACKET}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 38598 (\N{CJK UNIFIED IDEOGRAPH-96C6}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 21512 (\N{CJK UNIFIED IDEOGRAPH-5408}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 26834 (\N{CJK UNIFIED IDEOGRAPH-68D2}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12464 (\N{KATAKANA LETTER GU}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 12501 (\N{KATAKANA LETTER HU}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 38917 (\N{CJK UNIFIED IDEOGRAPH-9805}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)
## C:\Users\naruk\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\call.py:7: UserWarning: Glyph 30446 (\N{CJK UNIFIED IDEOGRAPH-76EE}) missing from current font.
## value, error = rpycall.call_r_function(f, *args, **kwargs)

month <- rep(c("1月", "2月", "3月"), each = 3)
neta <- rep(c("イカ", "タコ", "マグロ"), times = 3)
orders <- c(10, 40, 20, 20, 80, 50, 30, 90, 40)
library(ggplot2)
data <- data.frame(month, neta, orders)
ggplot(data, aes(x = neta, y = orders, fill = month)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "寿司屋の売り上げ",
x = "ネタ", y = "注文数 [百皿]") +
scale_fill_manual(values = c("1月" = "red", "2月" = "blue", "3月" = "green")) +
scale_y_continuous(breaks = seq(0, 100, by = 20)) +
theme_minimal()
