Put all names on bar chart

Hello, I am making a bar graph of the annual income for districts within each department. I have two problems, (i) when I make the bar graph not all the names of the districts appear and (ii) is there a format so that it does not appear on the x axis :x10 ^ 5 ?

I leave the code with a simulated data.

begin
	cantidad=1000
	data_1=DataFrame(
		distrito=[randstring(4) for i=1:cantidad],
		departamento=["Departamento_$i" for i in rand(1:24,cantidad)],
		ingreso=[1000000*rand() for i=1:cantidad]
	)
end

begin
	depa_1 = unique(data_1.departamento)
	se_1=depa_1.=>depa_1
	md" $(@bind depa_elegido Select(se_1))"
end

begin
	data_2=filter(row ->row.departamento==depa_elegido, data_1);
	sort!(data_2, [:ingreso]);
end;

begin
	plot(data_2.distrito, data_2.ingreso, legend=:false, orientation=:h, seriestype=:bar)
	title!("Departamento de $depa_elegido")
	xticks!(LinRange(0, maximum(data_2.ingreso), 4))
	xlims!(0, maximum(data_2.ingreso))
end

Check the following code (stripped out the notebook GUI stuff):

using Printf, DataFrames, Plots; gr(dpi=300)

cantidad = 1000
data_1 = DataFrame(
	distrito=[randstring(4) for i=1:cantidad],
	departamento=["Departamento_$i" for i in rand(1:24,cantidad)],
	ingreso=[1000000*rand() for i=1:cantidad] )
depa_1 = unique(data_1.departamento)
se_1 = depa_1.=>depa_1
depa_elegido = "Departamento_3"
data_2 = filter(row ->row.departamento==depa_elegido, data_1)
sort!(data_2, [:ingreso])

ny = length(data_2.distrito)
plot(data_2.distrito, data_2.ingreso, legend=:false, orientation=:h, seriestype=:bar)
yticks!(0.5:ny-0.5,data_2.distrito,ytickfontsize=4)
title!("Departamento de $depa_elegido")
x = LinRange(0, maximum(data_2.ingreso), 4)
str = [@sprintf("%i", xi) for xi in x]
xticks!(x,str, xlims=extrema(x),tickdir=:out,xtickfontsize=4)

2 Likes